I'm trying to create a method that takes a binary number as a string parameter and then prints out the decimal equivalent. For some reason my code isn't working but I feel like I am extremely close!
import java.util.Scanner; public class Question1 { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println(" Enter a binary number "); String n= input.nextLine(); int hey = binaryToDecimal(n) ; System.out.println(hey); } public static int binaryToDecimal(String num) { char number ; int n; int x = 0; int m=0; for(int i=0;i<=num.length()-1;i++) { number=num.charAt(i); n = Character.getNumericValue(number); m = num.length()-1; x +=n*Math.pow(2,m); m--; } return x; } }