Home > Net >  how to scan many time by using for function?
how to scan many time by using for function?

Time:10-13

import java.util.Scanner;
public class array2 {
    
     public static void main(String[]sef)
     {
         int a=0;
         int number[]=new int[20];
         Scanner scan=new Scanner(System.in);
         for(a=0;a<number.length;a  );   //**i want scan data many time**
         {
             System.out.println(a "번째 학생의 숫자를 입력하십시오");  
             number[a]=scan.nextInt();
             
         }
         scan.close();
         for(a=0;a<10;a  )
         {
             System.out.println(number[a]);   
         }
     }
}

i want to input data in arr many time. but i don't know how to do and i don't find answers in my language

CodePudding user response:

This looks like homework. That is the reason why I don't post a complete answer. You should be able to do it yourself when you learn more about loops. Hint: do...while

CodePudding user response:

I found some bugs in your code and I have added a few things to it. You can have a look at the snippet below.

import java.util.Arrays;
import java.util.Scanner;

public class array2 {

    public static void main(String[] args) {

        int number[] = new int[5];
        Scanner scan = new Scanner(System.in);
        for (int a = 0; a < number.length; a  ) {
            System.out.println(a   "번째 학생의 숫자를 입력하십시오");
            System.out.println("Please Enter a number");
            number[a] = scan.nextInt();
        }
        System.out.println(Arrays.toString(number));
        scan.close();

    }
}
  •  Tags:  
  • java
  • Related