這是一個相當基本的問題,但作爲一個新的Java學生它難倒我。這是我正在研究的一個實踐問題,無法弄清楚如何將hotOrColdOutside方法調用到main中。截至目前,它不是編譯和要求返回,但我的指令指定在這種情況下沒有參數或返回。我覺得這是我知道的簡單事情,但此時此刻正在探索我的頭腦,任何幫助我糾正這一情況都將值得讚賞。調用方法,其中包含if/else
import java.util.Scanner;
class TempExp
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
String answer = outsideTemp();
System.out.print(answer);
}//end main
public static String outsideTemp()
{
Scanner input = new Scanner(System.in);
System.out.print("What is the temperature outside: ");
int userIn = input.nextInt();
if(userIn >= 80)
{
System.out.print("It is very hot outside.");
}
else if(userIn >= 60)
{
System.out.print("It is very nice outside.");
}
else
{
System.out.print("It is very cold outside.");
}//end if/else
}//end method
}