Java ternary, three-way, ? Operator check factor

Question

We would like to write an application that reads two integers.

Check whether the first is a multiple of the second and prints the result.

Use the remainder operator.


import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        System.out.print("Enter two space separated integers: ");
        int x = sc.nextInt();
        int y = sc.nextInt();

        //your code here
    }/*from w  ww. ja va 2 s  . c  o  m*/
}



import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        System.out.print("Enter two space separated integers: ");
        int x = sc.nextInt();
        int y = sc.nextInt();

        System.out.printf("%d is%sa multiple of %d\n", x, (x % y == 0 ? " " : " not "), y);
    }
}



PreviousNext

Related