如何通过ForEach循环打印MutiDimension数组

时间:2019-06-16 18:12:13

标签: java

如何按照代码“帮助我”中的说明打印两个不同的数组,以打印这种类型的内部循环。

import java.util.Scanner;

public class hw_ass2_Store 
{

    public static void main(String[] args) 
    {
        System.out.println("+++ WELCOME TO VSQ STORE DATABASE SERVICE +++");
        Scanner s1=new Scanner(System.in);
        Scanner s2=new Scanner(System.in);

        System.out.print("\nEnter The No Of Product Details You Want To ADD : ");
        int size=s1.nextInt();
        int []itm = new int [size];

        for(int i=0;i<itm.length;i++)
        {
            System.out.print("Enter Product ID   : ");
            itm[i]=s1.nextInt();

            for(int i1=0;i1<1;i1++)
            {
                String []name = new String[size];
                System.out.print("Enter Product Name : ");
                String name1=s2.nextLine();
            }

        }

    for(int print1 : itm)
        {
            System.out.println(print1);
            for(int print2 : name)
            {
                System.out.println(print2);
            }
        }

    }
}

1 个答案:

答案 0 :(得分:0)

public static void main(String[] args) 
{
    System.out.println("+++ WELCOME TO VSQ STORE DATABASE SERVICE +++");
    Scanner s1=new Scanner(System.in);

    System.out.print("\nEnter The No Of Product Details You Want To ADD : ");
    int size=s1.nextInt();
    int[][] itm = new int[size][size];

    for(int i=0;i<size;i++)
    {
        System.out.print("Enter Product ID   : ");
        itm[i][0]=s1.nextInt();

        for(int i1=1;i1<size;i1++)
        {
            System.out.print("Enter Product Name : ");
            itm[i][i1]=s1.nextLine();
        }

    }
 int i=0;

for(int print1 : itm)
    {
        System.out.println(itm[i][0]);
        int i1=1;
        for(int print2 : name)
        {
            System.out.println(itm[i][i1]);
            i1++;
        }
        i++;
    }