We would like to check if a number is divisible by 3.
Read the integer from console.
import java.util.Scanner; public class Main { public static void main(String[] args) { /*from ww w. j a va 2s .c om*/ Scanner input = new Scanner(System.in); int x; System.out.print("Enter integer you wish to check: "); x = input.nextInt(); //your code here input.close(); } }
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner input = new Scanner(System.in); int x; System.out.print("Enter integer you wish to check: "); x = input.nextInt(); if (x % 3 == 0) System.out.println("Yep, it's divisible by 3!"); if (x % 3 != 0) System.out.println("Nope, it's not divisible by 3!"); input.close(); } }