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 :: request permission foreground service 
Java :: how to get the width and height of a string in java 
Java :: joptionpane.showconfirmdialog yes no example 
Java :: javascript remove specific character from string 
Java :: generate random letters and numbers in java 
Java :: how to set the text of a jlabel to bold 
Java :: spigot how to make an inventory 
Java :: converting string to int java 
Java :: array to map java 
Java :: int array to set in java 
Java :: How to change progressbar color xml android 
Java :: number of lines in file java 
Java :: internet access android manifest 
Java :: java uuid from string 
Java :: java get monitor size 
Java :: Duplicate class com.google.common.util.concurrent.ListenableFuture found in modules jetified-guava-24.1-jre (com.google.guava:guava:24.1-jre) and jetified-listenablefuture-1.0 (com.google.guava:listenablefuture:1.0) 
Java :: spigot get commandmap 
Java :: Spigot API inventory close 
Java :: how to print in java 
Java :: Recompile with -Xlint:deprecation 
Java :: javafx live date and time 
Java :: java string format .2f 
Java :: java botton code 
Java :: java create list with one element 
Java :: foreach not applicable to type - binary tree sort 
Java :: java convert double to string 
Java :: absolute method in jdbc 
Java :: open a new activity on click of a button 
Java :: button color xml android 
Java :: import for Collectors java 
ADD CONTENT
Topic
Content
Source link
Name
3+2 =