Switch to full style
Java2 codes,problems ,discussions and solutions are here
Post a reply

Need help with code for a while loop program

Fri Nov 19, 2010 4:49 am

I am not asking anyone to do my assignment for me, I just have no clue what I am suppose to do. I don't know where to start or what exactly the program is looking for. If someone would kindly explain or would help me out with this, I will definitely appreciate all the help I can get.

So my assignment is to write a program that used while loops to perform 6 different things.
1. prompt the users to input two integers: firstNum and secondNum (firstNum must be less than secondNum).
2. output all the odd numbers between firstNum 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 letter.
and lastly there is a hint: if currentNum % 2 = 0, then the currentNum is an even number. Otherwise it is an odd number.

Once again, I am not expecting or asking anyone to do a whole code or my entire assignment for me. I just really need help because I am so confused with the whole program. Thank You.



Re: Need help with code for a while loop program

Sun Nov 21, 2010 8:39 pm

hey brother,

Try to write some code and come so we help you in it ,!!!

Re: Need help with code for a while loop program

Sun Nov 28, 2010 2:24 am

1) for(onecounter = 1;onecounter <= 3; onecounter++)
{
System.out.println("Enter Number " + onecounter + " : ");
}

Re: Need help with code for a while loop program

Sun Nov 28, 2010 3:25 am

hehe

im gonna try this just for funnzies..:)

Re: Need help with code for a while loop program

Sun Nov 28, 2010 3:36 am

this is wut i got atm,maybe others can input as a grp assignment :p


Code:
 
import java
.util.Scanner//import scanner class

 
class loopsforumhelp
 
{
 
    public static 
void main(String[] args)
    {
 
 
   
int NumOne 0;  //inputted number one
   
int NumTwo 0;  //inputted number two

   
Scanner keyboard = new Scanner(System.in);  // holds input

        
        
           
for(int onecounter 1;onecounter <= 2onecounter++)
           {
             if(
onecounter == 1)
             {
                
System.out.println("Lowest Number First.");
                
System.out.println("Enter Number " onecounter " : ");
                    
NumOne keyboard.nextInt();
             }
             if(
onecounter == 2)
             {
                
System.out.println("Enter Number " onecounter " : ");
                    
NumTwo keyboard.nextInt();
             }
            }
            
        for(
int twocounter NumOne;twocounter <= NumTwo;twocounter+2;)
        {
                
System.out.println(twocounter);
        }        

 
}
}
 


Post a reply
  Related Posts  to : Need help with code for a while loop program
 How to link a c++ program with HTML code     -  
 Do while loop     -  
 do while loop and for loop C++ example help.     -  
 C++ While loop     -  
 While loop     -  
 Breaking a Loop     -  
 Why will my loop does not work     -  
 PIC Assembly For Loop Example     -  
 I NEED SOME HELP IN THE FOR LOOP PLZ .. IAM JUST A BEGINNER     -  
 Using include() Within a Loop     -