Help!!!

J

JScoobyCed

Aghost.temp said:
Hi,

Would anyone help me with the below

1).
a). Using a for loop write a program to display the numbers 1 to 10
inclusive as follows;

1
2
3
etc...

Ensure your program is as efficient as possible.

b). Modify the above program to se an if statement to display the
messasge "Even" next to all even
numbers and the message "Odd" against all odd numbers.

c). Repeat the above stages using while loops and do..while loops

2).

a). Use an array to store the cumulative total for each number, i.e

Number Cumulative Score
1 1
2 3
3 6
4 10
5 15

b). Modify the program to display all the numbers up to a cumulative
score of 100

3). Wire a method to calculate the cube (x*x*x) of each number an display
the answer to the last screen.


Thanks

Also clean my bedroom, brush my teeth...
 
R

Rob Shepherd

Aghost.temp said:
Hi,

Would anyone help me with the below

1).
a). Using a for loop write a program to display the numbers 1 to 10
inclusive as follows;

1
2
3
etc...

Ensure your program is as efficient as possible.

b). Modify the above program to se an if statement to display the
messasge "Even" next to all even
numbers and the message "Odd" against all odd numbers.

c). Repeat the above stages using while loops and do..while loops

2).

a). Use an array to store the cumulative total for each number, i.e

Number Cumulative Score
1 1
2 3
3 6
4 10
5 15

b). Modify the program to display all the numbers up to a cumulative
score of 100

3). Wire a method to calculate the cube (x*x*x) of each number an display
the answer to the last screen.


Thanks

looks like homework to me.

1. Why not have a go first and then ask for help when you get stuck.
2. comp.lang.java.help would be more appropriate when you have gotten stuck.

some references to help you

a) http://java.sun.com/docs/books/tutorial/java/nutsandbolts/for.html
b) http://java.sun.com/docs/books/tutorial/java/nutsandbolts/if.html
c) http://java.sun.com/docs/books/tutorial/java/nutsandbolts/while.html
d) http://java.sun.com/docs/books/tutorial/java/data/arrays.html

Good luck

Rob
 
T

Thomas Schodt

Aghost.temp said:
Hi,

Would anyone help me with the below

Please do not multipost.

You are likely to get the most useful responses
to a request like this in c.l.j.help
 
A

Aghost.temp

Hi,

Would anyone help me with the below

1).
a). Using a for loop write a program to display the numbers 1 to 10
inclusive as follows;

1
2
3
etc...

Ensure your program is as efficient as possible.

b). Modify the above program to se an if statement to display the
messasge "Even" next to all even
numbers and the message "Odd" against all odd numbers.

c). Repeat the above stages using while loops and do..while loops

2).

a). Use an array to store the cumulative total for each number, i.e

Number Cumulative Score
1 1
2 3
3 6
4 10
5 15

b). Modify the program to display all the numbers up to a cumulative
score of 100

3). Wire a method to calculate the cube (x*x*x) of each number an display
the answer to the last screen.


Thanks
 
H

Hari

Aghost.temp said:
Hi,

Would anyone help me with the below

1).
a). Using a for loop write a program to display the numbers 1 to 10
inclusive as follows;

1
2
3
etc...

Ensure your program is as efficient as possible.
public class First
{
public static void main(String args[])
{
for(int i = 1; i < 11; i++)
{
System.out.println(i);
}
}
}
b). Modify the above program to se an if statement to display the
messasge "Even" next to all even
numbers and the message "Odd" against all odd numbers.

public class Second
{
public static void main(String args[])
{
for(int i = 1; i < 11; i++)
{
System.out.print(i);
if(i % 2 == 0) System.out.print(" Even")
else System.out.print(" Odd")
System.out.println()
}
}
}
c). Repeat the above stages using while loops and do..while loops

2).

a). Use an array to store the cumulative total for each number, i.e

Number Cumulative Score
1 1
2 3
3 6
4 10
5 15


public class Third
{
public static void main(String args[])
{
int array[] = new int[101];
for(int i = 1; i < array.length; i++)
{
array = (i*(i+1))/2;
}
}
}

b). Modify the program to display all the numbers up to a
cumulative

Using this information you should be able to do the rest. -Hari
 
L

Liz

don't forget that your teacher might be reading this ng
(-_-)

Hari said:
Aghost.temp said:
Hi,

Would anyone help me with the below

1).
a). Using a for loop write a program to display the numbers 1 to 10
inclusive as follows;

1
2
3
etc...

Ensure your program is as efficient as possible.
public class First
{
public static void main(String args[])
{
for(int i = 1; i < 11; i++)
{
System.out.println(i);
}
}
}
b). Modify the above program to se an if statement to display the
messasge "Even" next to all even
numbers and the message "Odd" against all odd numbers.

public class Second
{
public static void main(String args[])
{
for(int i = 1; i < 11; i++)
{
System.out.print(i);
if(i % 2 == 0) System.out.print(" Even")
else System.out.print(" Odd")
System.out.println()
}
}
}
c). Repeat the above stages using while loops and do..while loops

2).

a). Use an array to store the cumulative total for each number, i.e

Number Cumulative Score
1 1
2 3
3 6
4 10
5 15


public class Third
{
public static void main(String args[])
{
int array[] = new int[101];
for(int i = 1; i < array.length; i++)
{
array = (i*(i+1))/2;
}
}
}

b). Modify the program to display all the numbers up to a
cumulative

Using this information you should be able to do the rest. -Hari
score of 100

3). Wire a method to calculate the cube (x*x*x) of each number an display
the answer to the last screen.


Thanks
 
A

Aghost.temp

thanks for that liz. THe last post came too late for me to use it, and
anyway - I worked it out myself.

Thanks for the reminder anyway

Liz said:
don't forget that your teacher might be reading this ng
(-_-)

Hari said:
Aghost.temp said:
Hi,

Would anyone help me with the below

1).
a). Using a for loop write a program to display the numbers 1
to
10
inclusive as follows;

1
2
3
etc...

Ensure your program is as efficient as possible.
public class First
{
public static void main(String args[])
{
for(int i = 1; i < 11; i++)
{
System.out.println(i);
}
}
}
b). Modify the above program to se an if statement to display the
messasge "Even" next to all even
numbers and the message "Odd" against all odd numbers.

public class Second
{
public static void main(String args[])
{
for(int i = 1; i < 11; i++)
{
System.out.print(i);
if(i % 2 == 0) System.out.print(" Even")
else System.out.print(" Odd")
System.out.println()
}
}
}
c). Repeat the above stages using while loops and do..while loops

2).

a). Use an array to store the cumulative total for each
number,
i.e
Number Cumulative Score
1 1
2 3
3 6
4 10
5 15


public class Third
{
public static void main(String args[])
{
int array[] = new int[101];
for(int i = 1; i < array.length; i++)
{
array = (i*(i+1))/2;
}
}
}

b). Modify the program to display all the numbers up to a
cumulative

Using this information you should be able to do the rest. -Hari
score of 100

3). Wire a method to calculate the cube (x*x*x) of each number an display
the answer to the last screen.


Thanks

 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,430
Messages
2,571,676
Members
48,796
Latest member
Greg L.

Latest Threads

Top