我创建了一个带有静态方法的项链类,该方法确定项链序列必须生成多少个数才能返回原始的两个数字。此外,该方法称为howLong,它将序列中的前两项作为参数。它会生成一个项链序列,并返回必须生成多少个数字才能返回原来的两个数字。我没有计算总数中的前两个数字,但确实计算了它们的最终生成时间。正如您可以看到下面的代码我在howLong方法中打印了一些东西 System.out.print(两个+“”); ,但它不应该打印任何东西。它应该使用一个调用howLong并打印结果的main方法。我该怎么办?
import java.util.Scanner;
public class Necklace {
public static int howLong (int firstStarting, int secondStarting) {
int sum = 0;
int temp;
int one = firstStarting;
int two = secondStarting;
do{
temp = (one + two) % 10;
one = two;
two = temp;
System.out.print(two + " ");
}while (two != secondStarting || one != firstStarting);
return (sum);
}
public static void main (final String[] args) {
int total;
int first;
int sec;
Scanner in = new Scanner (System.in);
System.out.print("Enter the first starting number: ");
first = in.nextInt();
System.out.print("Enter the second starting number: ");
sec = in.nextInt();
total = howLong (first, sec);
}
}