In: Computer Science
write java program that prompt the user to enter two numbers .the program display all numbers between that are divisible by 7 and 8 ( the program should swap the numbers in case the secone number id lower than first one please enter two integer number : 900 199 Swapping the numbers 224 280 336 392 448 504 560 616 672 728 784 840 896 i need it eclipse
For this program, we accept two integers from user. Then check if the first number is greater than second. if yes, then swap them.
Then using a for loop from first to second number, we determine if the number is divisible by both 7 and 8. If it is then display it.
CODE:
/******************************************************************************
Online Java Compiler.
Code, Compile, Run and Debug java program online.
Write your code in this editor and press "Run" button to execute
it.
*******************************************************************************/
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
Scanner sc = new
Scanner(System.in);
//accepting two numbers ffrom
user
System.out.print("Enter the first
number: ");
int num1 = sc.nextInt();
System.out.print("Enter the second
number: ");
int num2 = sc.nextInt();
if(num1 > num2) //checking if
first is greater that second
{
//swapping
int temp = num1;
num1 = num2;
num2 = temp;
}
System.out.println("Numbers
divisible by 7 and 8 are: ");
for(int i=num1; i<num2;
i++)
{
if(i%7 == 0 && i%8 == 0)
//divisibility check
{
System.out.print(i+" "); //print
number
}
}
}
}
OUTPUT: