Latest Tutorials| Questions and Answers|Ask Questions?|Site Map




Have Programming Question? Ask it here!
 
 
 


Pintu Ranjan Sai
Array
1 Answer(s)      3 years and a month ago
Posted in : Java Beginners


How do i insert elements into an array up to a limit from command prompt using SOP statement.like Enter range:3 Enter elements: 1 5 3


Advertisement
View Answers

July 25, 2011 at 10:52 AM


import java.util.*;
class  ArrayExample
{
    public static void main(String[] args) 
    {
     Scanner input=new Scanner(System.in);
     System.out.print("Enter Range: ");
     int size=input.nextInt();
     int array[]=new int[size];
     System.out.println("Enter Array Elements: ");
     for(int i=0;i<array.length;i++){
         array[i]=input.nextInt();
     }
     System.out.println("Your Array Elements are: ");
     for(int i=0;i<array.length;i++){
         System.out.println(array[i]);
     }
    }
}


Related Tutorials/Questions & Answers:
Advertisements
 

 

 

DMCA.com