0

hi everyone,
can anyone solve me the code for the java problem.

i need a java programthat holds twenty integers in an array, loop though each cell sequentially and prints each number on the console.

thank you very much.

shantuli

4
Contributors
8
Replies
9
Views
12 Years
Discussion Span
Last Post by tigerxx
0

Is this a basic Java I prodject? you should be able to look up arrays in your books index. There are a couple different ways to declare an array, one of which is;

int [] Intarr = new int[20];

int is the data type in this array, new int, creates the array, 20 is the number of positions. As for sequentially accessing it, do you know what a for loop is?

0

Something like this?

class ArrayOfInts
{
  public static void main(String[] args)
  {
     int[] myNums = new int[20];

    for (int x=0; x<20; x++)
    {
        myNums[x] = x * 5;
    }
   
    for (int y=0; y<myNums.length; y++)
	{
	  System.out.println("myNums[" + y + "] = " + myNums[y]);
	}
	 
  }
}
0

hi everyone,
can anyone solve me the code for the java problem.

i need a java programthat holds twenty integers in an array, loop though each cell sequentially and prints each number on the console.
thank you very much.

shantuli

tht's very easy

class Test{
    public static void main(String args[]){
        int[] arr = new int[20];
        for(int j=0;j<20;j++){
            arr[j]=j;
        }
        for(int i=0;i<arr.length;i++){            
            System.out.println(arr[i]);
        }
    }
}

arr is array containing 20 integers
this will print first 20 from 0 to 19
this will do the job

Edited by Reverend Jim: Fixed formatting

0

tht's very easy

class Test{
public static void main(String args[]){
int[] arr = new int[20];
for(int j=0;j<20;j++){
arr[j]=j;
}
for(int i=0;i<arr.length;i++){

System.out.println(arr);
}
}
}
arr is array containing 20 integers
this will print first 20 from 0 to 19
this will do the job

Of course it was easy for you. You basicly copied my code above.

0

Of course it was easy for you. You basicly copied my code above.

am practising java for more than 4 yrs
i don;t have to copy it from u
man .................

but if u thing ur great genous just keep it in ur mind only

no need to tell./............

0

Well what was the point in posting the same code twice when someone else already had?

hav u look at my code
it much simpler than urs

bye eat good and think good

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.