-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNameChecker .java
More file actions
28 lines (25 loc) · 964 Bytes
/
NameChecker .java
File metadata and controls
28 lines (25 loc) · 964 Bytes
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
import java.util.Scanner;
/**
* Ask the user for their name.
* Outputs each character entered by the user, on separate lines.
* Then outputs only letters from the name entered by the user, all on the same line.
*/
class NameChecker{
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
System.out.print("Enter your name: ");
String name = scanner.nextLine();
for(int i = 0; i < name.length(); i++){
//outputing all characters of the name on new lines
System.out.println(name.charAt(i));
}
for(int i = 0; i < name.length(); i++){
try{
Integer.parseInt(name.charAt(i) + ""); //checking if the character integer or not
}catch(Exception e){
System.out.print(name.charAt(i)); //outputing character if it is not number
}
}
scanner.close();
}
}