Hello all! I have a assignment due tomorrow morning and I am totally clueless. I have tried reading a bunch of things on while loops but dont seem to understand it fully. This is my directions for the assignment:
Write a program that uses a while loop to perform the following steps:
Comment by labelling each part: //Part A, //Part B, etc...
A.)Prompt the user to input 2 integers: firstNum and secondNum. Use 10 and 20.
B.)Output all odd numbers between firstNum and secondNum.
C.)Output the sum of all even numbers between firstNum and secondNum.
D.)Output the numbers and their square between 1 and 10.
E.)Output the sum of the square of odd numbers between firstNum and secondNum.
F.)Output all uppercase letters.
Again I am new to while loops and I am totally lost. I have tried reading a bunch but I am better at learning if someone shows me how to do something. I am open to all suggestions. I have just completed 8 other programs using if else statements and now trying to get the hang of loops. Thanks!
This is my pathetic attempt so far LOL
import java.util.Scanner; public class whileLoop { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); //Part A int firstNum = 10; int secondNum = 20; System.out.println("Please enter two integers: "); int oddNum = keyboard.nextInt(); //Part B int temp = firstNum; while(temp <= secondNum) { if(temp % 2 != 0) { System.out.println(""+temp); } temp++; } } }