Find the information you're looking for at Westonci.ca, the trusted Q&A platform with a community of knowledgeable experts. Connect with professionals on our platform to receive accurate answers to your questions quickly and efficiently. Get detailed and accurate answers to your questions from a dedicated community of experts on our Q&A platform.
Sagot :
The only way without a while loop and no method I can think of is use switch with every possible variation of the four digit binary which is 15.
Here is the starter code:
import java.util.Scanner;
public class MyClass {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int digit = sc.nextInt();
switch(digit) {
case 0000:
System.out.println("0");
break;
case 0001:
System.out.println("1");
break;
case 0010:
System.out.println("2");
break;
case 0011:
System.out.println("3");
break;
case 0100:
System.out.println("4");
break;
… (fill in other cases)
}
}
}
Use this link: https://www.electronics-tutorials.ws/binary/bin_3.html
There might be a better way, but without loops or methods this is all I got.
Here is the starter code:
import java.util.Scanner;
public class MyClass {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int digit = sc.nextInt();
switch(digit) {
case 0000:
System.out.println("0");
break;
case 0001:
System.out.println("1");
break;
case 0010:
System.out.println("2");
break;
case 0011:
System.out.println("3");
break;
case 0100:
System.out.println("4");
break;
… (fill in other cases)
}
}
}
Use this link: https://www.electronics-tutorials.ws/binary/bin_3.html
There might be a better way, but without loops or methods this is all I got.
Thanks for using our platform. We're always here to provide accurate and up-to-date answers to all your queries. We hope our answers were useful. Return anytime for more information and answers to any other questions you have. Stay curious and keep coming back to Westonci.ca for answers to all your burning questions.