我對這項任務沒有盡頭。看着它,我覺得括號和if else語句都是很好的。但是,錯誤說 「缺少return語句}」
_____________________________________________________________________^If Else If。在正確地形成退貨時遇到問題
public class CompareNums {
// TODO - write your code below this comment.
// The method you define will return one of three possible strings:
// - "less than": if the first parameter is less than the second
// - "equal to": if the first parameter is equal to the second
// - "greater than": if the first parameter is greater than the second
// Make sure you return _exactly_ the above strings
public static String comparison(int first, int second) {
if (first<second) {
return "less than";
} else if (first==second) {
return "equal to";
} else if (first>second) {
return "greater than";
}
}
// DO NOT MODIFY main!
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter first integer: ");
int first = input.nextInt();
System.out.print("Enter second integer: ");
int second = input.nextInt();
System.out.println("The first integer is " +
comparison(first, second) +
" the second integer.");
}
}