divute 클래스의 computeDivisor 클래스에있는 "compute"메서드를 인쇄하고 싶습니다. 제 약자가 누구인지 어떻게 알 수 있습니까?다른 클래스의 메소드 결과를 인쇄하는 방법은 무엇입니까?
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
computeDivisors cD = new computeDivisors();
System.out.println("Enter an integer: ");
int num = s.nextInt();
System.out.println("The divisors of " + num + " are: ");
cD.compute(); //Why doesn't it print?
s.close();
}
-
public void compute(){
for (i = 2; i <= num/2; i++) {
if (num % i == 0) {
System.out.print(i + " , ");
}
}
}
}
변수'num'을'public void compute()'에 어떻게 전달합니까? 매개 변수 여야합니까? – Andreas