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.println("Please enter 4 values");
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!!!
need help with program question
Page 1 of 13 Replies - 315 Views - Last Post: 04 May 2009 - 05:50 PM
Replies To: need help with program question
#2
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 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
Please next time
it helps us helping you
you are not correctlly reading the 4 values
int[] a = new int[4];
System.out.println("Please enter 4 values");
System.out.print ("This program will display the sum of Values entered");
for(int i = 0; i < 4; i++) {
a[i] = inp.nextInt();
}
//now you can add them
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
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 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
Please next time
it helps us helping you
you are not correctlly reading the 4 values
int[] a = new int[4];
System.out.println("Please enter 4 values");
System.out.print ("This program will display the sum of Values entered");
for(int i = 0; i < 4; i++) {
a[i] = inp.nextInt();
}
//now you can add them
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.putRadius (a);
S2.putDiameter (
System.out.println (" The Area of the Sphere is " S2.calcArea() + "The Volume of the Sphere is " + S2.calcVolume());
}
#4
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 ?
How can you hope to code if you can't even use an editor ?
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote



|