This is my solution in Java and I need your opinion:public class Main {  /**   *    */  public static void main(String[] args) {    Scanner in = new Scanner(System.in);    int number = in.nextInt();    in.close();    if (isPowerOfTwo(number)) {      System.out.println(yes);    } else {      System.out.printf(no);    }  }  private static boolean isPowerOfTwo(int number) {    if (number % 2 != 0) {      return false;    } else {      for (int i = 0; i <= number; i++) {        if (Math.pow(2, i) == number) return true;      }    }    return false;  }}
Checking if a number is power of 2 or not
java;interview questions;integer
try-with-resourcesSince Java 7, you should use try-with-resources on your Scanner for safe and efficient handling of the underlying I/O resource:public static void main(String[] args) {    try (Scanner scanner = new Scanner(System.in)) {        int number = scanner.nextInt();        // other operations    }}Mathematical approachYou may want to consider using a faster mathematical approach to test if the number is a positive power of two or not...boolean result = number > 0 && ((number & (number - 1)) == 0);\$1\$ is technically a power of two: \$2^0\$