I am writing a java program to compare two numbers using nesting methods but receiving the error`
class HelloWorld {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
System.out.println("Enter First Number");
int X = s.nextInt();
System.out.println("Enter Second Number");
int y = s.nextInt();
Nesting nest = new Nesting(int, int);
nest.disp();
}
}
class Nesting {
int m, n;
Nesting(int X, int y) {
m = X;
n = y;
}
int largest() {
if (m > n) {
return m;
} else {
return n;
}
}
void disp() {
int ans = largest();
System.out.println("My Result is " + ans);
}
}
While compiling receiving the following error
Line: 11
'.class' expected
Line: 11
'.class' expected
答案 0 :(得分:2)
When you call a method or constructor, you should not pass the type, instead you have to pass the values, you have to change :
Nesting nest = new Nesting(int, int);
To this :
Nesting nest = new Nesting(X, y);