Description
从键盘分别输入通过空格分割的整型(int)、浮点型(double)、字符型(String)、布尔型(boolean),根据读取的内容判断他们的类型并将他们解析为正确的对象,并都放到一个数组中。输出各个对象的类型
Input
字符串
Output
数据类型
Sample Input
2.1 true 123 abcde
Sample Output
double boolean int String
import java.util.*;
public class Main {
public static String type(String str)
{
int intflag = 0;
if(str.contains("."))
{
return "double";
}
if(str.contains("true") || str.contains("false") )
{
return "boolean";
}
for(int i = 0;i<str.length();i++)
{
if(str.charAt(i) >= '0' &&str.charAt(i) <= '9') {
intflag = 1;
}
else intflag = 0;
}
if(intflag == 1)
{
return "int";
}
//else
return "String";
}
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String str = scan.nextLine();
str = str + " ";
String temp = "";
String judge = "";
for(int i = 0;i<str.length();i++)
{
if(str.charAt(i) == ' ')
{
judge = judge + type(temp) +" ";
temp = "";
}
temp = temp + str.charAt(i);
}
judge = judge.substring(0,judge.length() - 1);
System.out.println(judge);
}
}