import java.io.*;
public class tempdetection {
public static int celciustofarenheit(int temp){
int fTemp = ((9 * temp)/5) + 32;
return fTemp;
}
public static void examineTemperature(int temp){
System.out.println("\nTemperature is " + temp + " in celcius. Hmmm...");
int fTemp = celciustofarenheit(temp);
System.out.println("\nThats " + fTemp + " in Farenheit...");
if(fTemp<20)
System.out.println("\n***Burrrr. Its cold...***\n\n");
else if(fTemp>20 || fTemp<50)
System.out.println("\n***The weather is niether too hot nor too cold***\n\n");
else if(fTemp>50)
System.out.println("\n***Holy cow.. Its scorching.. Too hot***\n\n");
}
public static void main(String[] args) throws IOException {
int temperature;
char c;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
do{
System.out.println("Input:\n(Consider the input is from the sensor)\n");
temperature = Integer.parseInt(br.readLine());
examineTemperature(temperature);
System.out.println("Does the sensor wanna continue giving input?:(y/n)\n");
c = (char) br.read();
}while(c!= 'N' && c!='n'); //if c==N that is no then stop
}
}
이것은 완전한 코드 사람입니다. 나는 아직도 내 대답을 얻지 못합니다 ... 그물에 많은 것을 검색했지만 아무 소용이 없습니다 .. 이미 누가 도움이되지만 그 딘 내 문제를 해결 .. 온도는 int .. 그래서 내가 문자열로 변환해야합니다. ?? 부재 중 하나에 의해 지정된 그런데 examineTemperature (온도)는 초기화되지 말하는 N 오류 발생으로 또한 난 .. 시도 캐치 시도 또한 Java : java.lang.NumberFormatException
Input:
(Consider the input is from the sensor)
45
Temperature is 45 in celcius. Hmmm...
Thats 113 in Farenheit...
***The weather is niether too hot nor too cold***
Does the sensor wanna continue giving input?:(y/n)
N
Input:
(Consider the input is from the sensor)
Exception in thread "main" java.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at tempdetection.main(tempdetection.java:33)
그것을 작동 Fyn이 반복하면서이 ... 때까지
'c = (char) br.readLine();'시도해주세요. –
@RongNK : 아니요, 오류가 실제로 여기에 있습니다 :'c '='N '|| c! = 'n' '. 그'||'는'&&'이어야합니다. – Mac
나는 변화했지만 아무 소용이 .. @Mac –