3 Replies - 23622 Views - Last Post: 01 October 2007 - 01:51 PM Rate Topic: -----

#1 quakeworld2007  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 71
  • Joined: 28-September 07

How to store values in an integer array

Posted 30 September 2007 - 06:47 PM

How would I store a and b in an array?

public class Squared {
	
	public static void main(String args[])
	{
		int a = 0, b = 0;
		for ( int number = 5; number <=10; number++)
		{
			if (number< 15)
			a =  (number );
			b= (number * number);
			
			System.out.println(a);

		}
							
	
}

}
[edit] added code tags PB

This post has been edited by jayman9: 30 September 2007 - 11:31 PM


Is This A Good Question/Topic? 0
  • +

Replies To: How to store values in an integer array

#2 PennyBoki  Icon User is offline

  • system("revolution");
  • member icon

Reputation: 53
  • View blog
  • Posts: 2,334
  • Joined: 11-December 06

Re: How to store values in an integer array

Posted 30 September 2007 - 06:59 PM

Hi there, this may not be a solution you want but it sure uses arrays, so try to consider it carefully. And please use code tags when posting code.

public class Squared {

public static void main(String args[])
{
int a[]={0,0,0,0,0,0} , b[]={0,0,0,0,0,0};
for ( int number = 5; number <=10; number++)
{

a[number-5] = number;
b[number-5]= (number * number);

System.out.println(a[number-5]);
System.out.println(b[number-5]);

}


}

}

This post has been edited by PennyBoki: 30 September 2007 - 07:00 PM

Was This Post Helpful? 0
  • +
  • -

#3 quakeworld2007  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 71
  • Joined: 28-September 07

Re: How to store values in an integer array

Posted 30 September 2007 - 07:26 PM

what does the -5 stand for?
Was This Post Helpful? 0
  • +
  • -

#4 PennyBoki  Icon User is offline

  • system("revolution");
  • member icon

Reputation: 53
  • View blog
  • Posts: 2,334
  • Joined: 11-December 06

Re: How to store values in an integer array

Posted 01 October 2007 - 01:51 PM

Because in the for loop number starts from 5 and the index of the arrays starts from 0.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1