aboutsummaryrefslogtreecommitdiff
path: root/challenge-002/abigail/java/ch-2.java
blob: 8c15c6ed49288120e7d5981f922504693825cc20 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//
// See https://theweeklychallenge.org/blog/perl-weekly-challenge-002
//

//
// Run as: ln ch-2.java ch2.java; javac ch2.java; java ch2 < input-file
//

import java.util.*;

public class ch2 {
    public static void main (String [] args) {
        Boolean from_base = false;
        Boolean to_base   = false;

        if (args . length == 1) {
            if (args [0] . equals ("-f")) {
                from_base = true;
            }
            if (args [0] . equals ("-t")) {
                to_base   = true;
            }
        }

        Scanner scanner = new Scanner (System . in);
        while (scanner . hasNextLine ()) {
            String line = scanner . nextLine () . trim ();
            if (from_base) {
                System . out . println (Integer . parseInt (line, 35));
            }
            if (to_base) {
                System . out . println (Integer . toString (
                                        Integer . parseInt (line), 35) .
                                                  toUpperCase ());
            }
        }
    }
}