I have to write a program in java which uses while loops. 1.prompt the user to input two intergers: firstnum ans second numnumber. (first number must be smaller that the second number). 2. Output all the even numbers between first number and second number inclusive. 3. Output the sum of all the even number between first number and second number inclusive. 4 Output all the odd numbers between first number and second number inclusive. 5. Output the sum of all the odd numbers between first number and second number inclusive
The solution to the above question is given below with screenshot of output.
=====================================================
I kept the logic simple and i have tested all outputs.
If there is anything else do let me know in comments.
=====================================================
============ CODE TO COPY ===============================
main.java
import java.util.Scanner; // Import the Scanner class
class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int sum_even = 0;
int sum_odd = 0;
System.out.println();
// Taking first number from user
System.out.print("Enter first number: ");
int first_number = scanner.nextInt();
// Taking second number from user
System.out.print("Enter second number: ");
int second_number = scanner.nextInt();
// if second number if smaller ask again
while( second_number < first_number ){
System.out.print("Second number smaller, enter again : ");
second_number = scanner.nextInt();
}
// Output all the even numbers between first number and second number inclusive
System.out.println();
System.out.print("Even numbers between first number and second number inclusive: ");
for ( int i = first_number ; i <= second_number; i++){
if ( i % 2 == 0 ){
System.out.print(i + " ");
sum_even += i;
}
}
System.out.println();
System.out.print("Sum of all the even number between first number and second number inclusive : ");
System.out.print(sum_even);
// Output all the odd numbers between first number and second number inclusive
System.out.println();
System.out.println();
System.out.print("Odd numbers between first number and second number inclusive: ");
for ( int i = first_number ; i <= second_number; i++){
if ( i % 2 != 0 ){
System.out.print(i + " ");
sum_odd += i;
}
}
System.out.println();
System.out.print("Sum of all the odd number between first number and second number inclusive :");
System.out.println(sum_odd );
}
}
=====================================================
Output :

I have to write a program in java which uses while loops. 1.prompt the user to...
write the program in VBA
b. Write a program that uses a For loop 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 odd numbers between firstNum and secondNum. c. Output the sum of all odd numbers between firstNum and secondNum. d. Output all even numbers between firstNum and second Num. e. Output the sum of all even numbers between firstNum and secondNum.
Write a Java program to prompt for inputting an integer N, then enter N integers (a loop is needed), print the numbers user entered, and the amount of even and odd numbers (zero is even number). (1) Prompt for the user to input an integer and output the integer. (1 pts) Enter an integer: You entered: 5 (2) Prompt for the user to input N integers, output the numbers entered and the amount of even and odd numbers (9 pts)...
using c++ write a program that reads numbers from the user until the user enters a Sentinel. Use a Sentinel of -999. Ignore all negative numbers from the user input. Do the following: must use loops and numbers to do this 1. Output the sum of all even numbers 2. Output the sum of all odd numbers 3. Output the count of all even numbers 4. Output the count of all odd numbers
Use a java program that does the following:
. (10 points) Write a program as follows a. Prompt the user to input two positive integers: nl and n2 (nl should be less than n2) b. If the user enters the negative number(s), convert it/them to positive number(s) c. If nl is greater than n2, swap them. d. Use a while loop to output all the even numbers between nl and n2 e. Use a while loop to output the sum...
In java, write a program that gets 10 integer numbers from the user using user input, and then calculates and display the sum of the numbers that have been read. Program Requirements: Write the program in three versions with three loops. Put all three loops in the main method of your source code. The program must be in one file. version1: use a while loop. version2: use a do-while loop. version 3: use a for loop. For each version, use a loop to...
Write a program with loops that compute a.The sum of all even numbers between 2 and 100 (inclusive). b.The sum of all squares between 1 and 100 (inclusive). c.All powers of 2 from 20 up to 220. d.The sum of all odd numbers between a and b (inclusive), where a and b are inputs. Note*: For part d, enter 3 and 21 as input Output should be: a. 2550 b. 338350 c. 1.0 2.0 4.0 8.0 ... 1048576.05 d. 120
In java, write a program that gets 10 integer numbers from the user using user input, and then calculates and display the sum of the numbers that have been read. Program Requirements: Write the program in three versions with three loops. Put all three loops in the main method of your source code. version1: use a while loop. version2: use a do-while loop. version 3: use a for loop. For each version, use a loop to input 10 int numbers from the user...
Q1. Write a program in Java a. Create 2 separate arrays, of user defined values, of same size b. Add these 2 arrays. ........................................................................................................................... Q2. Write a program in java (using loop) input any10 numbers from user and store in an array. Check whether each of array element is positive, negative, zero, odd or even number. ............................................................................................................................ Q3. Write a program in Java to display first 10 natural numbers. Find the sum of only odd numbers. .............................................................................................................................. Q4....
Write a single program in java using only do/while loops for counters(do not use array pls) for the majority of the program and that asks a user to enter a integer and also asks if you have any more input (yes or no) after each input if yes cycle again, if not the program must do all the following 4 things at the end of the program once the user is finished inputting all inputs... a.The smallest and largest of...
Write a Java program that prompts the user for the page size used in a virtual memory system; this will be a power of two between 512 (29) and 16384 (214), inclusive. Your program should check the user input for page size to make sure it is one of the allowable inputs (must be a power of 2 and cannot be smaller than 512 or larger than 16384), and should then prompt the user for a virtual address (assume 32-bit...