inherit
148188
0
Oct 14, 2009 7:29:08 GMT -8
boobookatie7
1
October 2009
boobookatie7
|
Post by boobookatie7 on Oct 14, 2009 7:19:00 GMT -8
Hi everyone! I am new to ProBoard, so this is my first time using it. I am an online college student and I am taking a Java course right now and have an assignment I need help with. My instructor is not necessarily helping with my questions, so I turn to you for advice. Here are the requirements for this program. Write a program using While loops to perform the following steps: 1. Prompt the user to input two integers: firstNum and secondNum. (firstNum must be less than secondNum). 2. Output all the odd numbers between fristNUm and secondNum inclusive. 3. Output the sum of all the even numbers between firstNum and secondNum inclusive. 4. Output all the numbers and their squares between 1 and 10. 5. Output the sum of the squares of all the odd numbers between firstNum and secondNum inclusive. 6. Output all the uppercase letters.
So I have 1-3 done and run smoothly in NetBeans. Here is what I have for number 4: //for squares for (number = firstNum + 1; firstNum <= secondNum; number++) if (number%2 <= 10) System.out.println("The number is" + number + "The square is" + square); It just continues to run. Any suggestions, and he did say we could use for loops. I need this explained in terms I can understand and if you could help in any way, it is greatly appreciated! Thanks
|
|
Former Member
inherit
guest@proboards.com
155872
0
Dec 4, 2024 8:55:29 GMT -8
Former Member
0
January 1970
Former Member
|
Post by Former Member on Oct 14, 2009 7:26:03 GMT -8
It runs forever because even though you're changing variable number, firstNum is never being changed, therefore firstNum is always less or equal to secondNum.
|
|
inherit
100824
0
May 13, 2012 5:37:49 GMT -8
Michael
14,585
March 2007
wrighty
|
Post by Michael on Oct 14, 2009 15:32:39 GMT -8
I have done something to help you. I've done ... #1, #2, and #3.
The rest of the areas you can do based on what I have coded for you ... What's more, I am not using your variable names so that you then have to read through the code and work out what is what.
Your #6 makes no sense what so ever.
Code: import java.util.Scanner;
class BooBoo { public static void main(String[] args) { Scanner kybd = new Scanner(System.in); System.out.println("Enter 2 integers..."); int x = kybd.nextInt(), y = kybd.nextInt(), t = 0; if(x > y) System.out.println("The first number must be less than the second."); else{ for(int i = x; i < y; i++){ if(i % 2 == 0) t += i; else System.out.println(i); } System.out.println("Total of even numbers is " + t); } } }
Let me know if you need any further help.
|
|