-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
49 lines (48 loc) · 1.87 KB
/
Main.java
File metadata and controls
49 lines (48 loc) · 1.87 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
import java.util.Scanner;
class Main {
public static void main(String[] args) {
System.out.print("\033[H\033[2J");
System.out.println("What character(s) do you want to load into the cannon?");
Scanner inputcharObj = new Scanner(System.in);
String inputchar = inputcharObj.nextLine();
System.out.println("Enter the amount of times you want " + "'" + inputchar + "'" + " to be fired from the cannon:");
Scanner inputnumtimesObj = new Scanner(System.in);
boolean inputgoodornot = false;
String inputnumtimes = "";
while (inputgoodornot == false) {
inputnumtimes = inputnumtimesObj.nextLine();
int inputlength = inputnumtimes.length();
int keeptrack = 0;
inputgoodornot = true;
while (keeptrack < inputlength) {
if (inputnumtimes.charAt(keeptrack) >= '0' && inputnumtimes.charAt(keeptrack) <= '9') {
keeptrack = keeptrack + 1;
}
else if (inputnumtimes.substring(0,1).equals("-")) {
inputgoodornot = false;
System.out.println("Error: Entered number must not be negative. Try again?");
break;
}
else {
inputgoodornot = false;
System.out.println("Error: User input must not include characters other than numbers. Try again?");
break;
}
}
}
System.out.print("\033[H\033[2J");
long numoftimes = Long.parseLong(inputnumtimes);
String inputcharforprint = inputchar + " ";
int linelengthchecker = 0;
for (int i = 0; i < numoftimes; i++) {
System.out.print(inputcharforprint);
linelengthchecker = linelengthchecker + 1;
if (linelengthchecker > 120) {
System.out.println();
linelengthchecker = 0;
}
}
System.out.println("");
System.out.println("'" + inputchar + "'" + " was printed " + numoftimes + " times");
}
}