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

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?

Intarr is just the name I gave the array

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]);
	}
	 
  }
}

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

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.

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./............

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.