Computer Science, asked by akshayakhuntia06, 7 months ago

enter any 2 numbers and show first number is divisible by second number or not.If not divisible then display 2 numbers which is divisible by 2nd no nearer to 1st no​..Pls write a java program for it...The correct one would be given brainliest mark​​

Answers

Answered by udayagrawal49
6

Answer:

import java.util.Scanner;

public class Main {

public static void main(String[] args) {

 try{

  Scanner scan = new Scanner(System.in);

  int num1 = scan.nextInt();

  int num2 = scan.nextInt();

  scan.close();

  if (num1 % num2 == 0){

   System.out.println(num1+" is divisible by "+num2);

  }

  else {

   int n = num1 % num2;

   int n1 = num1-n;

   int n2 = num1+(num2-n);

   System.out.println(num1+" is not divisible by "+num2+". Two numbers which are divisible by "+num2+" and are nearer to "+num1+" are "+n1+" and "+n2);

  }

 }

 catch (Exception e) {

  System.out.println("Invalid Numbers");

 }

}

}

Please mark it as Brainliest.

Similar questions