How to store values in an integer array

Page 1 of 1

3 Replies - 32251 Views - Last Post: 01 October 2007 - 01:51 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=34358&amp;s=46f2268290ee2cd42c1d4ccf126f8f80&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

#1 quakeworld2007

• D.I.C Head

Reputation: 3
• 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);

}

}

}
 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

• D.I.C Lover

Reputation: 55
• Posts: 2,345
• 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

• D.I.C Head

Reputation: 3
• 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

• D.I.C Lover

Reputation: 55
• Posts: 2,345
• 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

 .related ul { list-style-type: circle; font-size: 12px; font-weight: bold; } .related li { margin-bottom: 5px; background-position: left 7px !important; margin-left: -35px; } .related h2 { font-size: 18px; font-weight: bold; } .related a { color: blue; }