Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
java初学者-打印表_Java_Arrays - Fatal编程技术网

java初学者-打印表

java初学者-打印表,java,arrays,Java,Arrays,我正在打印0-99之间的值和食物数组中的随机字符串。我似乎无法正确地将它们输出到表中 String foods[] = {"Bread", "Pizza", "Cheese"}; for (int x = 0; x<=99; x++) { for (int i = 0; i<4; i++) { int random = (int) (Math.random() * 3); System.out.print(x + " - " + f

我正在打印0-99之间的值和食物数组中的随机字符串。我似乎无法正确地将它们输出到表中

String foods[] = {"Bread", "Pizza", "Cheese"};
for (int x = 0; x<=99; x++) {
      for (int i = 0; i<4; i++) {
          int random = (int) (Math.random() * 3);
          System.out.print(x + " - " + foods[random] + "\t\t");
      }
    System.out.println();
}
预期产出:

0 - Pizza      1 - Bread     2 - Cheese    3 - Bread
4 - Bread      5 - Pizza     6 - Bread     7 - Pizza
.... until 99

这将完成以下工作:

    String foods[] = {"Bread", "Pizza", "Cheese"};
    for (int x = 1; x<=100; x++) {

              int random = (int) (Math.random() * 3);
              System.out.print((x-1) + " - " + foods[random] + "\t\t");
              if(x%4==0)
                  System.out.println();


    }
String foods[]={“面包”、“比萨饼”、“奶酪”};

对于(int x=1;x而言,问题在于,只有在运行内部for并打印整行之后,才增加x

String foods[] = {"Bread", "Pizza", "Cheese"};
    for (int x = 0; x <= 99; ) {
        for (int i = 0; i < 4; i++) {
            int random = (int) (Math.random() * 3);
            System.out.print(x + " - " + foods[random] + "\t\t");
             x++;
        }
        System.out.println();
    }
String foods[]={“面包”、“比萨饼”、“奶酪”};
对于(int x=0;x请尝试此代码
import java.io.*;
类开发
{
公共静态void main(字符串[]args)
{
串食物[]={“面包”、“比萨饼”、“奶酪”};

for(int x=0;x)那么您想要的输出是什么呢?另一个注意事项是:尝试在所有代码中保持一致。在这种情况下,在for语句中始终使用'
String foods[] = {"Bread", "Pizza", "Cheese"};
    for (int x = 0; x <= 99; ) {
        for (int i = 0; i < 4; i++) {
            int random = (int) (Math.random() * 3);
            System.out.print(x + " - " + foods[random] + "\t\t");
             x++;
        }
        System.out.println();
    }
import java.io.*;
class dev
{
public static void main (String[] args)
{
   String foods[] = {"Bread", "Pizza", "Cheese"};
        for (int x = 0; x<=99; x++) 
          {
             System.out.print(x + "  -" + foods[ (int) (Math.random() * 3)] + " \t\t");
              if(x%4==0) System.out.println();
           }
 }}