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
Program
import java.util.*; //this package is used to import scanner class
class Main
{
public static void main(String[] args) {
int num1,num2,i,temp; //num1 and num2 are for storing numbers ,i loop variable, temp -temporary variable
int flag=0;
Scanner in = new Scanner(System.in); //Scanner type object in is created for taking input from user
System.out.println("Please enter two integers:"); //taking input numbers from user
num1=in.nextInt();
num2=in.nextInt();
if(num1>num2) //this is for swapping the values if first number is greater than Second number
{ //swapping values using temporary variable
flag=1; //to understand that swapping is done here
temp=num1;
num1=num2;
num2=temp;
}
if(flag==1)
System.out.print("Swapping the numbers\n");
for(i=num1;i<=num2;i++) // this loop will work from value num1 to num2
{
if(i%7==0 && i%8==0) // if the number is divisible by both 7 and 8
{
System.out.print(i+" "); /* for print the values div by both 7 and 8 they are separated by two blank spaces */
}
}
}
}
sample output
If you find this useful ,please rate positive , thankyou