Home Answers Viewqa Java-Beginners program that uses while loops to perform the following steps :

 
 


Rajeswary Govindasamy
program that uses while loops to perform the following steps :
1 Answer(s)      8 months ago
Posted in : Java Beginners

Write a program that uses while loops to perform the following steps : a. Prompt the use to input two integers : FirstNum and secondNum.( FirstNum must be less than secondNum.) b. Output all the odd numbers between firstNum and secondNum inclusive. c. Output the sum of all the ven number between FirstNum and secondNum inclusive. d. Output all the numbers and their squares between 1-10. e. Output the sum of the squares of all the odd numbers between firstNum and secondNum inclusive f. Output all the uppercase letters.

(java coding: pls help me)

View Answers

September 20, 2012 at 5:51 PM


Here is your required code:

import java.util.*;
public class NumberExample{
    public static void main(String[]args){
        int sum=0,sumSquares=0;
        int num1=0,num2=0;
    Scanner input=new Scanner(System.in);
    System.out.print("Enter First Number: ");
     num1=input.nextInt();

    System.out.print("Enter Second Number: ");
     num2=input.nextInt();

    if(num1>num2){
    System.out.print("Your First Number is greater than second.So Please re-enter: ");
    num1=input.nextInt();
    }
    else{
        System.out.println("Odd Numbers: ");
while(num1 <= num2) {
if(num1%2 != 0) {
System.out.println(num1);
sumSquares+=(num1*num1);
}
if(num1%2 == 0) {
sum+=num1;
}
num1++;
}
System.out.println("Sum Of Even Numbers: "+sum);
System.out.println("Numbers and their squares between 1 and 10");
int i=1;
while(i <= 10) {
System.out.println(i+"    "+(i*i));
i++;
}
System.out.println("Sum Of square of odd Numbers: "+sumSquares);
}
    }
}









Related Pages:

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.