Using Java:
Write a program that uses while loops to perform the following steps:
a. Prompt the user 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 even numbers between firstNum and secondNum inclusive.
d. Output all the numbers and their squares between 1 and 10.
e. Output the sum of the squares of all the odd numbers between firstNum and secondNum inclusive.
f. Output all the uppercase letters.
Guide On Rating System
Vote
Here is a Java program that performs the steps mentioned:
```java
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// Step a
System.out.print("Enter first number: ");
int firstNum = scanner.nextInt();
System.out.print("Enter second number: ");
int secondNum = scanner.nextInt();
// Step b
System.out.print("Odd numbers between " + firstNum + " and " + secondNum + ": ");
int currentNum = firstNum;
while (currentNum <= secondNum) {
if (currentNum % 2 != 0) {
System.out.print(currentNum + " ");
}
currentNum++;
}
System.out.println();
// Step c
int sumOfEvens = 0;
currentNum = firstNum;
while (currentNum <= secondNum) {
if (currentNum % 2 == 0) {
sumOfEvens += currentNum;
}
currentNum++;
}
System.out.println("Sum of even numbers between " + firstNum + " and " + secondNum + ": " + sumOfEvens);
// Step d
System.out.println("Numbers and their squares between 1 and 10:");
int number = 1;
while (number <= 10) {
System.out.println(number + " - " + number * number);
number++;
}
// Step e
int sumOfOddSquares = 0;
currentNum = firstNum;
while (currentNum <= secondNum) {
if (currentNum % 2 != 0) {
sumOfOddSquares += (currentNum * currentNum);
}
currentNum++;
}
System.out.println("Sum of squares of odd numbers between " + firstNum + " and " + secondNum + ": " + sumOfOddSquares);
// Step f
System.out.print("Uppercase letters: ");
char letter = 'A';
while (letter <= 'Z') {
System.out.print(letter + " ");
letter++;
}
System.out.println();
scanner.close();
}
}
```
This program prompts the user to enter two integers, firstNum and secondNum. It then performs the steps mentioned:
a. Prompt the user 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 even numbers between firstNum and secondNum inclusive.
d. Output all the numbers and their squares between 1 and 10.
e. Output the sum of the squares of all the odd numbers between firstNum and secondNum inclusive.
f. Output all the uppercase letters.
After performing these steps, the program ends.