使用javac编译此简单代码,会给我以下错误
Test3.java:38:错误:表达式的非法开头
public static int minFun(int a,int b){
我试图在主变量之外声明变量(即public static int a,b,c),但没有任何改变。
自从我遵循this tutorial以来,使用了非常相似的示例代码,这使我感到困惑。
在此先感谢您的帮助。
// Program to output the minimum of two integer numbers
import java.io.*;
public class Test3 {
public static void main (String args[]) {
int a, b, c;
String rA, rB;
InputStreamReader input = new InputStreamReader (System.in);
BufferedReader keyboard = new BufferedReader (input);
System.out.println ("Please, enter two integer numbers.");
try {
rA = keyboard.readLine ();
a = Integer.parseInt (rA);
rB = keyboard.readLine ();
b = Integer.parseInt (rB);
}
catch (IOException e) {
System.err.println ("Not a proper integer number.");
}
catch (NumberFormatException e) {
System.err.println ("Not a proper integer number.");
}
c = minFun (a, b);
if (a != b) {
System.out.println ("The smaller number is " + c);
}
else {
System.out.println ("The two numbers are equals.");
}
public static int minFun (int a, int b) {
int min;
if (a < b) {
min = a;
}
else {
min = b;
}
return min;
}
}
答案 0 :(得分:2)
if (a != b) {
System.out.println ("The smaller number is " + c);
}
else {
System.out.println ("The two numbers are equals.");
} // <----- was not present
此行缺少大括号。