need help with program question

Page 1 of 1

3 Replies - 717 Views - Last Post: 04 May 2009 - 05:50 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=103360&amp;s=9c5515febd73299857cfcd493dbd96ca&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

#1 Bwall

Reputation: 0
• Posts: 6
• Joined: 04-May 09

need help with program question

Posted 04 May 2009 - 04:49 PM

I need to write a short program to which contains "for" loops which will demonstrate that the value of the variable isum at the termination of the each loop is 17.

it also must contain
int a[] = {2,3,5,7};
with a[0] through a[3] being a[0]=2, a[1]=3, a[2]=5, a[3]=7;

int isum = 0
for (int i = 0; i<4; ++i)
isum += a[i];

thats is everything that needs to be included, this is what I have so far but i dont think that it is correct

import java.util.Scanner;

public class Assign1
{
public static void main (Strings args[])
{
Scanner inp = New Scanner(System.in);
System.out.print ("This program will display the sum of Values entered");
int i = inp.nextInt();
int A[] = new (int[4]);
int isum;
for (int i = 0; i < 4; ++i)
isum += a[i];

System.out.println(The sum of the values entered is ) + isum;
}

}
}

If anyone could help me out ASAP it would be greatly appreciated!!!

Is This A Good Question/Topic? 0

Replies To: need help with program question

#2 pbl

• There is nothing you can't do with a JTable

Reputation: 8378
• Posts: 31,956
• Joined: 06-March 08

Re: need help with program question

Posted 04 May 2009 - 05:02 PM

Bwall, on 4 May, 2009 - 03:49 PM, said:

I need to write a short program to which contains "for" loops which will demonstrate that the value of the variable isum at the termination of the each loop is 17.

it also must contain
int a[] = {2,3,5,7};
with a[0] through a[3] being a[0]=2, a[1]=3, a[2]=5, a[3]=7; Yes it is written the previous line

it helps us helping you

you are not correctlly reading the 4 values

```int[] a = new int[4];
System.out.print ("This program will display the sum of Values entered");
for(int i = 0; i < 4; i++) {
a[i] = inp.nextInt();
}

for(int i = 0; i < 4; i++) {
isum = isum + a[i];
}

```

Actually you can have calculated isum in the first loop no need to make 2 loops

```for(int i = 0; i < 4; i++) {
a[i] = inp.nextInt();
isum = isum + a[i];
}

```

Actually you don't even need an array
```for(int i = 0; i < 4; i++) {
isum = isum + inp.nextInt();
}

```

And next time:

This post has been edited by pbl: 04 May 2009 - 05:14 PM

#3 Bwall

Reputation: 0
• Posts: 6
• Joined: 04-May 09

Re: need help with program question

Posted 04 May 2009 - 05:16 PM

pbl, on 4 May, 2009 - 04:02 PM, said:

Bwall, on 4 May, 2009 - 03:49 PM, said:

I need to write a short program to which contains "for" loops which will demonstrate that the value of the variable isum at the termination of the each loop is 17.

it also must contain
int a[] = {2,3,5,7};
with a[0] through a[3] being a[0]=2, a[1]=3, a[2]=5, a[3]=7; Yes it is written the previous line

it helps us helping you

you are not correctlly reading the 4 values

```int[] a = new int[4];
System.out.print ("This program will display the sum of Values entered");
for(int i = 0; i < 4; i++) {
a[i] = inp.nextInt();
}

for(int i = 0; i < 4; i++) {
isum = isum + a[i];
}

```

Actually you can have calculated isum in the first loop no need to make 2 loops

```for(int i = 0; i < 4; i++) {
a[i] = inp.nextInt();
isum = isum + a[i];
}

```

Actually you don't even need an array
```for(int i = 0; i < 4; i++) {
isum = isum + inp.nextInt();
}

```

And next time:

Do you have any clue where I went wrong with this program??? my teacher said I am close on my assignments but not quite there.

import ASphere.MySphere;

import java.util.Scanner;
public class MySphere {
public static void main ( String [] args ) {
Scanner inp = new Scanner (System.in);
System.out.println ("Please enter the value of the radius and then the value of the diameter of the Sphere");
int a = 0
int b = 0
a = inp.nextInt ();
B = inp.nextInt ();
MySphere S1 = new MySphere (a, ;
MySphere S2 = new MySphere ();
System.out.println (" The Radius of the Sphere is " + S1.getRadius() + " And the Diameter is " + S1.getDiameter());
S2.putDiameter (;
System.out.println (" The Area of the Sphere is " S2.calcArea() + "The Volume of the Sphere is " + S2.calcVolume());
}

#4 pbl

• There is nothing you can't do with a JTable

Reputation: 8378
• Posts: 31,956
• Joined: 06-March 08

Re: need help with program question

Posted 04 May 2009 - 05:50 PM

Hey !!! Ho !!!

How can you hope to code if you can't even use an editor ?