0% found this document useful (0 votes)
2 views3 pages

Array 1D - Create - Input - Display - by Prashant Tandon

The document provides Java code samples for creating, inputting, and displaying one-dimensional arrays of different data types (int, String, float) based on user-defined sizes. Each sample includes a class definition and methods to accept user input and display the values stored in the arrays. The examples are intended for Class 10 students and are created by a computer teacher.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

Array 1D - Create - Input - Display - by Prashant Tandon

The document provides Java code samples for creating, inputting, and displaying one-dimensional arrays of different data types (int, String, float) based on user-defined sizes. Each sample includes a class definition and methods to accept user input and display the values stored in the arrays. The examples are intended for Class 10 students and are created by a computer teacher.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

For Class 10 # Created by Prashant Tandon, Computer Teacher, SMC Kanpur # Mobile 9839575830

1D Array – Create, Input & Display


Sample 1 : Create an OneD Array of int as per the size provided by User, Then Input / accept values
for an array & Display all the array values.

import java . util . * ;


class Array1_Scanner_int
{
public static void main( int N )
{
Scanner SC = new Scanner( System.in );
int ARR [ ] = new int [ N ] ; // value of N provided by User
int k ;
System.out.println( " Enter the Integer values for an Array : " ) ;
for( k = 0 ; k < ARR.length ; k++ )
{
System.out.print( "\t Enter the value for ARR[ " + k + " ] : " );
ARR[k] = SC.nextInt( );
}

System.out.println( "\n Given values are : " );


for( k =0 ; k < ARR.length ; k++ )
{
System.out.print( "\t" + ARR[k] );
}

} // end of main
} // end of class

For Class 10 # Created by Prashant Tandon, Computer Teacher, SMC Kanpur # Mobile 9839575830
Page No 1 of 3
For Class 10 # Created by Prashant Tandon, Computer Teacher, SMC Kanpur # Mobile 9839575830
Sample 2 : Create an OneD Array of String (to store Names) as per the size provided by User, Then

Input / accept values for an array & Display all the array values.

import java . util . * ;


class Array2_Scanner_String
{
public static void main( int N )
{
Scanner SC = new Scanner( System.in );
String NAMES [ ] = new String [ N ] ; // value of N provided by User
int k ;
System.out.println( " Enter the Student Names for an Array : " ) ;
for( k = 0 ; k < NAMES.length ; k++ )
{
System.out.print( "\t Enter any Name for ARR[ " + k + " ] : " );
NAMES[ k ] = SC.nextLine( );
}

System.out.println( "\n Given Names are : " );


for( k =0 ; k < NAMES.length ; k++ )
{
System.out.print( "\t" + NAMES [k] );
}

} // end of main
} // end of class

For Class 10 # Created by Prashant Tandon, Computer Teacher, SMC Kanpur # Mobile 9839575830
Page No 2 of 3
For Class 10 # Created by Prashant Tandon, Computer Teacher, SMC Kanpur # Mobile 9839575830
Sample 3 : Create an OneD Array of float as per the size provided by User, Then Input / accept

values for an array & Display all the array values.

import java . util . * ;


class Array3_Scanner_float
{
public static void main( int N )
{
Scanner SC = new Scanner( System.in );
float [ ] NUM = new float[ N ] ; // value of N provided by User
int k ;
System.out.println( " Enter the Floating-Point values for an Array : " ) ;
for( k = 0 ; k < NUM.length ; k++ )
{
System.out.print( "\t Enter any value for NUM[ " + k + " ] : " );
NUM[k] = SC.nextFloat( );
}

System.out.println( "\n Given Floating-Point values are : " );


for( k =0 ; k < NUM.length ; k++ )
{
System.out.print( "\t" + NUM[k] );
}

} // end of main
} // end of class

For Class 10 # Created by Prashant Tandon, Computer Teacher, SMC Kanpur # Mobile 9839575830
Page No 3 of 3

You might also like