While loop

Write a program that uses while loop to perform the following steps:
a. Prompt the user to enter first number and second number. (First must be less than second number)
b. Output all odd numbers between first and second number.
c. Output all the number and their squares.
d. output the sum of all squares.


I'm done with a and b. I don't know how to do the c and d. Please help!



Scanner input=new Scanner(System.in);
System.out.print("Enter First Number: ");
x=input.nextInt();

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

if(x>y){
System.out.print("Your First Number is greater than second.So Please re-enter: ");
x=input.nextInt();
}

else {

System.out.print("\tOdd Numbers: ");
x++;
while(x < y) {
if(x%2 != 0) {
System.out.print(" " + x);
}
x++;
}
}
closed account (Dy7SLyTq)
first of all... thats java in a c++ beginners section... secondly do u know the standard power function that i believe is designed the same for each language?
Topic archived. No new replies allowed.