import java.util.Scanner;
class Quiz4 {
public static void main(String args[]){
char repeat = userInput.charAt(0);
do{
Scanner input = new Scanner( System.in );
System.out.println("Enter a binary number ");
String binaryString =input.nextLine();
if (binaryString.matches("[10]+")) {
System.out.println ("You entered " +binaryString );
System.out.println("Its base of 10 equivalent is "+Integer.parseInt(binaryString,2));
} else {
System.out.println ("Try again ");
}while (repeat == 'Y' || repeat == 'y');
}
}
}
Im writing a code that converts binary to decimal, I've gotten pretty much everything done except I have to make sure the program continues working until user prompts it to stop. Im not sure how to apply it to my code. I know I have use a do/while loop but im not sure how to apply it.
import java.util.Scanner;
class Quiz4 {
public static void main(String args[]){
Scanner input = new Scanner( System.in );
System.out.println("Enter a binary number ");
String binaryString =input.nextLine();
if (binaryString.matches("[10]+")) {
System.out.println ("You entered " +binaryString );
System.out.println("Its base of 10 equivalent is "+Integer.parseInt(binaryString,2));
} else {
System.out.println ("Try again ");
}
}
}