Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (7k points)
edited by
I am new to Java and I want my Java code to take input from the user for an integer array, how can I do it?

1 Answer

0 votes
by (13.1k points)

You can do something like this:

import java.util.*;

public class Main

{

public static void main(String[] args) {

Scanner sc=new Scanner(System.in);

int[] arr=new int[5];

for(int i=0;i<arr.length;i++){

    arr[i]=sc.nextInt();

}

for(int i=0;i<arr.length;i++){

    System.out.println(arr[i]);

}

    

}

}

Want to learn Java? Check out the Java course from Intellipaat.

Related questions

0 votes
1 answer
0 votes
0 answers
0 votes
1 answer
asked Mar 9, 2021 in Java by dante07 (13.1k points)
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...