Write a program which convert Binary number to Decimal in java?
package javatute;
import java.io.IOException;
import java.util.Scanner;
public class BinaryToDecimal {
public static void main(String[] args) throws IOException {
Scanner in = new Scanner(System.in);
System.out.print("Enter a Binary number");
String s = in.nextLine();
long n = Long.parseLong(s);
long r;
while (n > 0) {
r = n % 10;
n = n / 10;
if (r != 0 && r != 1) {
System.out.println("This is not a binary numberber");
}
}
int i = Integer.parseInt(s, 2);
System.out.println("Decimal:" + i);
}
}