Home > Back-end >  Why small white help run wrong
Why small white help run wrong

Time:10-04

 package Test4; 

import java.util.Scanner;

Class A {
int a;
Int b;
Int a1.
Int b1.
Int getGCD () {
Scanner s=new Scanner (System. In);
System. The out. Println (" please enter a positive integer a value ");
A=s.n extInt ();
System. The out. Println (" please enter a positive integer value b ");
B=s.n extInt ();
S.c lose ();
int temp;
If (aTemp=a;
A=b;
B=temp.
}
A1=a;
B1=b;
While (b!=0) {
Temp=a % b;
A=b;
B=temp.
}
System. The out. Println (a1 + "and" + b1 + "is the greatest common divisor" + a);
Return a;
}

}

Class B {
A x=new A ();
Void getLCM () {
System. The out. Println (x.a 1 + "and" 1 + + x.b "is the least common multiple of" + (x.b x.a 1 * 1)/x.g etGCD ());
}
}

Public class Test4_4 {
Public static void main (String [] args) {
A. A=new A ();
Atul gawande etGCD ();
B B=new B ();
B.g etLCM ();
}

}

CodePudding user response:

The s.c lose (); Comment out you performed a was shut down

CodePudding user response:

Your code Scanner shut down, so called after complains, will be s.c lose (); Comment out;
Did you call in the class B class A member variable a1 and b1, because before you use this variable does not have the assignment, so the two values in A class B is the default value is 0, pay attention to the member variable and the scope of local variables,

CodePudding user response:

reference source on the second floor is a ghost reply:
close the Scanner in your code, so called after complains, will be s.c lose (); Comment out;
Did you call in the class B class A member variable a1 and b1, because before you use this variable does not have the assignment, so the two values in A class B is the default value is 0, pay attention to the member variable and the scope of local variables,

Speak very detailed

CodePudding user response:

reference 1st floor usecf response:
the s.c lose (); Comment out when you finish perform a closed

Good good drops (?????? Omega?)?
  • Related