-
Notifications
You must be signed in to change notification settings - Fork 1
/
var.java
47 lines (40 loc) · 1.26 KB
/
var.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
import java.util.Scanner;
public class A{
public static void countTypeInString(String string){
String[] value = string.split(" ");
double ifFloat;
int ifInt;
String ifString;
int counter = 0;
for (String i: value){
try{
ifFloat = Double.parseDouble(i);
counter++;
continue;
} catch (NumberFormatException e){
}
}
System.out.println("Double " + counter);
counter = 0;
for (String i: value){
try{
ifInt = Integer.parseInt(i);
counter++;
continue;
} catch (NumberFormatException e){
}
}
System.out.println("Int " + counter);
String stringOfStrings = string.replaceAll("[0-9.]","");
stringOfStrings = stringOfStrings.replaceAll(" "," ");
String[] value2 = stringOfStrings.split(" ");
System.out.println("String " + value2.length);
}
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the string");
String string=sc.nextLine();
System.out.println(string);
countTypeInString(string);
}
}