http://e-tutor.itsa.org.tw/e-Tutor/mod/programming/view.php?id=671
這題輸入到字串然後轉成陣列判斷它的長度假如是1就是字元,大於1並且字元ASCii>'0'就是字串 str.contains(".")判斷是否有小數點若有則為浮點數,其餘皆為整數 這題測資並沒有個位數字0~9假如要個位數判斷就在第10行增加&& c[0] > '9'判斷就行了
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
while (scn.hasNext()) {
String str = scn.nextLine();
char c[] = str.toCharArray();
if (c.length == 1)
System.out.println("char");
else if (c.length > 1 && c[0] > '9')
System.out.println("string");
else if (str.indexOf('.') > 0)
System.out.println("float");
else
System.out.println("int");
}
}
/*
題目:[C_CH06-易] 判斷輸入變數的形式
作者:1010
時間:西元 2016 年 7 月 */
}