twenty integers in an array

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jul 2004
Posts: 16
Reputation: shantuli is an unknown quantity at this point 
Solved Threads: 0
shantuli shantuli is offline Offline
Newbie Poster

twenty integers in an array

 
0
  #1
Oct 14th, 2004
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
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 7
Reputation: tiberis is an unknown quantity at this point 
Solved Threads: 0
tiberis tiberis is offline Offline
Newbie Poster

Re: twenty integers in an array

 
0
  #2
Oct 14th, 2004
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?
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 7
Reputation: tiberis is an unknown quantity at this point 
Solved Threads: 0
tiberis tiberis is offline Offline
Newbie Poster

Re: twenty integers in an array

 
0
  #3
Oct 14th, 2004
Intarr is just the name I gave the array
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

Re: twenty integers in an array

 
0
  #4
Oct 14th, 2004
Something like this?

  1. class ArrayOfInts
  2. {
  3. public static void main(String[] args)
  4. {
  5. int[] myNums = new int[20];
  6.  
  7. for (int x=0; x<20; x++)
  8. {
  9. myNums[x] = x * 5;
  10. }
  11.  
  12. for (int y=0; y<myNums.length; y++)
  13. {
  14. System.out.println("myNums[" + y + "] = " + myNums[y]);
  15. }
  16.  
  17. }
  18. }
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 35
Reputation: tigerxx is an unknown quantity at this point 
Solved Threads: 0
tigerxx tigerxx is offline Offline
Light Poster

Re: twenty integers in an array

 
0
  #5
Oct 14th, 2004
Originally Posted by shantuli
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
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

Re: twenty integers in an array

 
0
  #6
Oct 15th, 2004
Originally Posted by tigerxx
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
Of course it was easy for you. You basicly copied my code above.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 35
Reputation: tigerxx is an unknown quantity at this point 
Solved Threads: 0
tigerxx tigerxx is offline Offline
Light Poster

Re: twenty integers in an array

 
0
  #7
Oct 17th, 2004
Originally Posted by server_crash
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./............
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

Re: twenty integers in an array

 
0
  #8
Oct 18th, 2004
Well what was the point in posting the same code twice when someone else already had?
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 35
Reputation: tigerxx is an unknown quantity at this point 
Solved Threads: 0
tigerxx tigerxx is offline Offline
Light Poster

Re: twenty integers in an array

 
0
  #9
Oct 18th, 2004
Originally Posted by server_crash
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
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC