Java 打印阵列中的图案时出现问题
我试图从数组中获取要打印的图案数量,但在我的图案数量下,没有打印出对。这是我试图获取的示例Java 打印阵列中的图案时出现问题,java,numbers,Java,Numbers,我试图从数组中获取要打印的图案数量,但在我的图案数量下,没有打印出对。这是我试图获取的示例 (Array: 2 7 2 3 1 5 7 4 3 6 Number of patterns: 3) 但我不知道要从多少个模式中写出什么 守则: public class FindIt { /** * @param args the command line arguments */ public static void main(String[] args)
(Array: 2 7 2 3 1 5 7 4 3 6
Number of patterns: 3)
但我不知道要从多少个模式中写出什么
守则:
public class FindIt {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
int Sum = 0;
int[] InsertNumbers = new int[10];
System.out.println("Sample output #1:");
System.out.print("Array: ");
for(int i = 0; i < 10; i++)
{
InsertNumbers[i]=(int)(Math.random()*10)+1;
System.out.print(InsertNumbers[i] + " ");
}
System.out.println("");
System.out.print("Array: ");
for(int i = 0; i < 5; i++)
{
ComputePattern(InsertNumbers, Sum);
System.out.print(InsertNumbers[i] + " ");
}
System.out.println("");
System.out.print("Number of patterns: ");
}
public static void ComputePattern(int[] InsertNumbers, int Sum)
{
for(int i = 0; i < 2; i++)
{
InsertNumbers[i] = Sum;
Sum = Sum + Sum;
}
}
}
没有打印任何模式,因为在打印了大量模式后,您没有打印语句。很难理解您的代码,但以下是我可以告诉您的。 您已经设法询问用户输入,但我觉得下面的方法会更好 相反,尝试使用两个数组,一个用户可以输入10个整数,另一个数组包含对的总和,因此数组包含5个整数 借助For循环和公式,您可以使用它来获得两个连续的值。第一个公式是x*2,第二个公式是x*2+1。 在for循环中x为0,循环5次 然后,得到数组中x*2和x*2+1的值,并将它们相加 然后,通过求和,您可以使用它来计算模式的计数
建议:尽量与您的println和print保持一致。这很令人困惑,我也不太清楚为什么要为某些文本设置println,而为其余文本设置print。什么是模式对?