JAVA
Ask the user for two numbers. Print only the even numbers between them. You should also print the two numbers if they are even.
Sample Run 1:
Enter two numbers:
3
11

4 6 8 10
Sample Run 2:
Enter two numbers:
10
44

10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44

Respuesta :

import java.util.Scanner;

public class JavaApplication57 {

   

   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;

       }

   }

   

}

I hope this helps!

The program is an illustration of loops.

Loops are used to carry out repetition operations; examples are the for-loop and the while-loop.

The program in Java, where comments are used to explain each line is as follows:

import java.util.*;

public class Main{

public static void main(String[] args) {

    //This creates a Scanner object

 Scanner input = new Scanner(System.in);

 //This prompts the user for inputs

 System.out.println("Enter two numbers: ");

 //This gets input for the first number

 int a = input.nextInt();

 //This gets input for the second

 int b = input.nextInt();

 //This iterates from the first number to the second

 for(int i = a; i<=b;i++){

     //The following if condition checks, if the current number is even

     if(i%2 == 0){

         //If yes, the number is printed

         System.out.print(i+" ");

     }

 }

}

}

At the end of the program, all even numbers between the interval are printed.

See attachment for sample run

Read more about similar programs at:

https://brainly.com/question/19742578

Ver imagen MrRoyal
ACCESS MORE