Solved:

Checkmark

Answered by AI, Verified by Human Experts

Unit 4: Lesson 2 - Coding Activity 1

Unit 4: Lesson 2 - Coding Activity 1Ask the user for two numbers. Print only the even numbers between them. You should also print the two numbers if they are even.

Starter code:
import java.util.Scanner;

public class U4_L2_Activity_One{
public static void main(String[] args){

Scanner scan = new
Scanner(System.in);
System.out.println("Enter two numbers:");
int num1 = scan.nextlnt();
int num2 = scan.nextlnt();
while (num1 <= num2){
if (num1 %2==0){
system.out.print(num1="");
}
num+=1;
}
}
}

Final answer:The given code is a Java program that asks the user for two numbers and prints all the even numbers between them.Explanation:The given code is a Java program that asks the user for two numbers and prints all the even numbers between them.To achieve this, the program uses a while loop to iterate from the first number to the second number. Inside the loop, it checks if each number is even using the modulo operator (%). If a number is even, it is printed using the System.out.print() method.Here is the corrected code:import java.util.Scanner;public class U4_L2_Activity_One {public static void main(String[] args) {Scanner scan = new Scanner(System.in);System.out.println("Enter two numbers:");int num1 = scan.nextInt();int num2 = scan.nextInt();while (num1 <= num2) {if (num1 % 2 == 0) {System.out.print(num1 + " ");}num1 += 1;}}}...

Unlock full access for 72 hours, watch your grades skyrocket.
For just $0.99 cents, get access to the powerful quizwhiz chrome extension that automatically solves your homework using AI. Subscription renews at $5.99/week.