-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
62 lines (50 loc) · 1.76 KB
/
Main.java
File metadata and controls
62 lines (50 loc) · 1.76 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import java.util.Scanner;
// Press Shift twice to open the Search Everywhere dialog and type `show whitespaces`,
// then press Enter. You can now see whitespace characters in your code.
public class Main {
public static void main(String[] args) {
// Press Alt+Enter with your caret at the highlighted text to see how
// IntelliJ IDEA suggests fixing it.
Logic l = new Logic();
Scanner scan = new Scanner(System.in);
// while-loop to repeat this code until correct input
while (true) {
System.out.println("Type 'e' to encode, 'd' to decode: ");
String encORdec = scan.nextLine();
if (encORdec.equalsIgnoreCase("e")) {
String ptext = "";
// try-catch block in case of errant input
try {
System.out.println("Type text to encode: ");
ptext = scan.nextLine();
} catch (Exception e) {
System.out.println("Error. Invalid input. Try again.");
}
System.out.println(l.encode(ptext.toUpperCase()));
scan.close();
break;
} else if (encORdec.equalsIgnoreCase("d")) {
String etext = "";
// try-catch block in case of errant input
try {
System.out.println("Type text to decode: ");
etext = scan.nextLine();
} catch (Exception e) {
System.out.println("Error. Invalid input. Try again.");
}
System.out.println(l.decode(etext.toUpperCase()));
scan.close();
break;
} else {
System.out.println("Invalid input. Try again.");
}
}
// System.out.printf("Hello and welcome!\n");
// // Press Shift+F10 or click the green arrow button in the gutter to run the code.
// for (int i = 1; i <= 5; i++) {
//
// // Press Shift+F9 to start debugging your code. We have set one breakpoint
// // for you, but you can always add more by pressing Ctrl+F8.
// System.out.println("i = " + i);
}
}