Java輸入流學習(讀取整數(shù)方法)
/*題目:利用條件運算符的嵌套來完成此題:學習成績>=90分的同學用A表示,60-89分之間的用B表示,60分以下的用C表示。*/
關鍵代碼:
BufferedReader is = new BufferedReader(new InputStreamReader(System.in));
String strIn = is.readLine();
int i = Integer.parseInt(strIn);
所有代碼:
public static void main(String[] args) {
// TODO Auto-generated method stub
/*題目:利用條件運算符的嵌套來完成此題:學習成績>=90分的同學用A表示,60-89分之間的用B表示,
60分以下的用C表示。*/
int i=90;
try
{
BufferedReader is = new BufferedReader(new InputStreamReader(System.in));
String strIn = is.readLine();
i = Integer.parseInt(strIn);
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
char str=(i>=90)?'A':(i>=60)?'B':'C';
System.out.print(str);
};