Featured Post

Thursday, May 11, 2017

Java program to initialise an array, reading and displaying array elements onto the screen


import java.util.Scanner;
class stringdemo           /* stringdemo.java*/
{
  public static void main(String args[])
  {
   Scanner s=new Scanner(System.in);
    int a[]=new int[10];
    int i,n;
    System.out.println("enter your range");
    n=s.nextInt();
    for(i=0;i<n;i++)
    a[i]=s.nextInt();  /* reading integer values from the keyboard and placing then into array a*/
    System.out.println(); /* just the cursor goes to new line*/
    for(i=0;i<n;i++)
    System.out.println(a[i]); /* printing all the array values */
  }
}

Output:
D:\cjuschools>javac stringdemo.java
D:\cjuschools>java stringdemo
enter your range
5
12
23
34
45
56

12
23
34
45
56

/* int[] a=new int[5]; and int a[]=new int[5]; both are same and a is an array of size 5*/

                                           Next


oops through java,inheritance,interface,package,super keyword, program demonstrating the use of super keywork,abstract class,static,main,awt,swings,jtab,layout,panel,applet,param,Frame,JFrame, swingutilities.invokeLater,swingutilities.invokeanwait,multithreading, multiprocesing,start(),init() paint(),adapter class,inner class,annonymous inner class,outer class,packages,friendly, constrcutors,destructors,garbage collector,inheritance,encapusulation,abstraction,bytecode,compiler,interpreter,jdbc,jsp pages,exception handling

No comments:

Post a Comment