-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathLoops.java
executable file
·49 lines (42 loc) · 1.49 KB
/
Loops.java
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;
public class Loops {
public static void main(String[] args) {
boolean shouldContinue = true;
while (shouldContinue) {
System.out.println("Enter a string of alphanumeric characters"
+ " (exit to quit):");
String input = new Scanner(System.in).nextLine();
int digitCount = 0, letterCount = 0;
for (int i = 0; i < input.length(); ++i) {
char c = input.charAt(i);
if (Character.isDigit(c)) {
digitCount++;
}
if (Character.isAlphabetic(c)) {
letterCount++;
}
}
System.out.printf("Input contained %d digits and %d letters.%n",
digitCount, letterCount);
shouldContinue = (input.equalsIgnoreCase("exit")) ? false : true;
}
for (int i = 0; i < 10; ++i) {
System.out.println("Meow!");
}
String mystery = "mnerigpaba";
String solved = "";
int len = mystery.length();
for (int i = 0, j = len - 1; i < len / 2; ++i, --j) {
solved = solved + mystery.charAt(i) + mystery.charAt(j);
}
System.out.println(solved);
// If you uncomment either of these for-ever loops,
// you'll have to use Ctrl-C to stop the program.
//for (;;) {
// ever
//}
// while (true} {
// // forever
// }
}
}