Java question
Hello, Im learning java and im currently writing a program that multiplies a number from the user (6) and multiplies that number with 23. The thing is that i am not allowed to use the * operator and NO loops, just the leftshift operator (<<). The problem is 23*6=138, but it gives me a different number. Here is the code i tried: import java.util.Scanner; public class Multiplication { public static void main(String[] args) { Scanner scan = new Scanner(System.in); System.out.println("Multiply N by 23"); //23*6=138 System.out.print("Input N: "); int N = scan.nextInt(); //6 = 0110 int Z = 23; // 0001 0111 int result; if(N==0) result=0; else result= (16<<N)+(4<<N)+(2<<N)+N; //System.out.println("23*"+N+ "= "+ (Z<<2)); //System.out.println((16<<N)+(4<<N)+(2<<N)+N); System.out.println(result); } }