Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

how to get an array as input in java

    public class TakingInput {

    public static void main(String[] args) {

        Scanner s = new Scanner(System.in);

        System.out.println("enter number of elements");

        int n=s.nextInt();

        int arr[]=new int[n];

        System.out.println("enter elements");

        for(int i=0;i<n;i++){//for reading array
            arr[i]=s.nextInt();

        }

        for(int i: arr){ //for printing array

            System.out.println(i);

        }


    }

}
Comment

array input java

int n;  
Scanner sc=new Scanner(System.in);  
System.out.print("Enter the number of elements you want to store: ");  
//reading the number of elements from the that we want to enter  
n=sc.nextInt();  
//creates an array in the memory of length 10  
int[] array = new int[10];  
System.out.println("Enter the elements of the array: ");  
for(int i=0; i<n; i++)  
{  
//reading array elements from the user   
array[i]=sc.nextInt();  
}  
Comment

PREVIOUS NEXT
Code Example
Java :: chemistry formula on android 
Java :: example of throws clause in method 
Java :: docker how to pass params to spring boot application 
Java :: how to get map with string as key and Arraylist as value in java 
Java :: origin model color 
Java :: how to generate a random number in libgdx 
Java :: Java Super Power java 
Java :: correct lcd initialize 
Java :: Java Enable assertion in class names 
Java :: kakao tech tcp close_wati 
Java :: how do I change the opacity of a JButton 
Java :: bukkit java get max players 
Java :: setting up javafx in eclipse 
Java :: can abstract class have constructor in java 
Java :: remove part of string java 
Java :: java lambda function 
Java :: instanceof operator java 
Java :: java program to print vowels in a string 
Java :: nested for loop java 
Java :: Exception in Application start method java.lang.reflect.InvocationTargetException 
Java :: is string a primitive data type/use of getclass() 
Java :: java in 5 minutes 
Java :: array srting line by line in textview android 
Sql :: sql disable safe mode 
Sql :: select not matching data with join table 
Sql :: oracle create directory 
Sql :: copy table oracle 
Sql :: mysql show databases 
Sql :: sql not start with vowel 
Sql :: pl sql escape & 
ADD CONTENT
Topic
Content
Source link
Name
1+3 =