-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDigitNumberExtract.java
More file actions
41 lines (36 loc) · 1.19 KB
/
DigitNumberExtract.java
File metadata and controls
41 lines (36 loc) · 1.19 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
import java.util.Scanner;
public class DigitNumberExtract {
public static void main(String[] args)
{
Scanner scanner = new Scanner(System.in);
System.out.print("Please input Letters contains digit number : ");
String input = scanner.next();
String result = "";
String digit = "";
String letter = "";
for(int i=0; i < input.length(); i++)
{
char ch = input.charAt(i);
// if(Character.isDigit(ch)) //if integer
// {
// result += ch; //result = result + ch
// }
// if(Character.isSpace(ch)) //space
// {
// result += ch; //result = result + ch
// }
// 2nd method
if(Character.isDigit(ch)) //if integer
{
digit += ch; //result = result + ch
}else{
letter += ch;
}
}
// System.out.println("Digit numbers : " + result);
System.out.println("Digit numbers : " + digit);
System.out.println("Letters : " + letter);
System.out.println("Uppercase letters : " + letter.toUpperCase());
System.out.println("Lower letters : " + letter.toLowerCase());
}
}