java以前的筆記(三)
java的輸入大家知道java中的輸出語(yǔ)句是System.out.println(”寫上要輸出的語(yǔ)句“);
可有沒有知道java中的輸入語(yǔ)句又是怎樣的呢?
找了很多的資料終于被我找到了點(diǎn)頭緒了··
哈哈 ··好高興···
看看這個(gè)的輸入 ·
public static void main(String[] args) throws IOException{
InputStreamReader reader = new InputStreamReader(System.in);
BufferedReader input = new BufferedReader(reader);
System.out.print("Enter the number: ");
String text = input.readLine();
}
InputStreamReader reader = new InputStreamReader(System.in);
BufferedReader input = new BufferedReader(reader);
System.out.print("Enter the number: ");
String text = input.readLine();
}
這段代碼實(shí)在太長(zhǎng)了·
我想簡(jiǎn)化點(diǎn)·
能不能不要那個(gè)throws IOException 把那個(gè)去掉··結(jié)果是程序無法編譯的結(jié)果。
后來又想··在網(wǎng)上尋找別的更簡(jiǎn)便的輸入方法··
終于看到了
Java5.0以后可以使用java.util.Scanner類:
Scanner sc = new Scanner(System.in);
int i = sc.nextInt();
long l = sc.nextLong();
float f = sc.nextFloat();
double d = sc.nextDouble();
String s = sc.nextLine();
int i = sc.nextInt();
long l = sc.nextLong();
float f = sc.nextFloat();
double d = sc.nextDouble();
String s = sc.nextLine();
這個(gè)多簡(jiǎn)單啊··
來得實(shí)在··
這樣就簡(jiǎn)單多了··
posted on 2009-07-16 09:14 duduli 閱讀(923) 評(píng)論(0) 編輯 收藏 所屬分類: java