1. Ask the user to enter the number in binary format.
2. Check to see that the number entered is actually in binary format (starts with a '1' and only has '0's and '1's).
- If the user input is something that is not correct, then ask the user to re-enter the number. Make sure you respond appropriately so the user has some idea of what went wrong.
/***********************CheckBinary.java*****************/
import java.util.Scanner;
public class CheckBinary {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.print("Enter Binary
String: ");
String input = scan.nextLine();
boolean status = false;
while (!status) {
for (int i = 0; i < input.length(); i++) {
if (input.charAt(0) == '1' && (input.charAt(i) == '0' || input.charAt(i) == '1')) {
status = true;
}
if (!status) {
System.out.print("Enter
correct binary number: ");
input =
scan.nextLine();
}
}
}
System.out.println("Binary number
is: "+input);
scan.close();
}
}
/**************output**********************/
Enter Binary String: 01111
Enter correct binary number: 1001010101010
Binary number is: 1001010101010
Please let me know if you have any doubt or modify the answer, Thanks:)
1. Ask the user to enter the number in binary format. 2. Check to see that...
This is in python. I need to ask the user to enter some numbers, average, min, max, and sort them in numerical order. I also have to check that the user actually entered a number and if they didn't to just skip over that input but still execute based on the numbers they did enter. This is what I have so far. def randomList(userInput): while True: userInput = eval(input("Enter some numbers:")) randomList = [] randomList.append(userInput) return sum(randomList)/len(randomList)
In C:Write a program that can determine whether a user input is a binary number or not. (1, 2, 3, 8, 13) Write a program that accomplishes all of the following: Greets the user and informs them that the program will determine whether an input from the user is a valid binary number or not (e.g., consisting of only 0’s and/or 1’s). Accept an integer input from the user. Assume that the user provides a valid numeric input that will...
This program will ask the user to enter a number of players, then ask the user for each player's name and score. Once all of the players have been entered, the program will display a bar chart with each of their scores scaled as a percentage of the maximum score entered. See below for details on exactly how this should work - an example transcript of how the program should work is shown below (remember that values entered by the...
Write a program called telephone.java that prompts the user to enter their phone number using the specific format: (xxx) xxx-xxxx. The program should check whether the input entered is valid. The program must also check for the parenthesis () for the area code (the first three numbers). Example: (702)892-0516 would be correct but 702-892-0516 would not be correct. Example: Enter your phone number: 702-908-1333. 702-908-1333 is a NOT a valid phone number as there are no parenthesis (). Another example:...
Need help with code using pointer only in C Ask the user to enter a number between 1 and 10 •Check if the user has complied. •Keep asking the user for a number between 1 and 10 until the user complies. •Then calculate N! (no recursion)
Prepare pseudocode for a program that lets a user continuously enter numbers until the number 99 is entered. Once the user has stopped entering numbers, display the number of numbers entered AND the sum of those numbers. You'll need a counter and an accumulator for this (see pp. 179-181 and 205-208). Make sure your loop is structured (see priming input in figure 3-16). Don't forget to comment your code. Don't forget to display appropriate prompts when requesting input from the...
Ask uFor Ex. "Prompt user to enter a number" = user enters 10, your program should output 1, 2, 3, 4, 5, 6, 7, 8, 9, 10.ser to input a number, and then using a loop control statement (While, For, Do-While), output to the console the numbers beginning from 1, up to and including the number input by the user.
This assignment is about data types and condition checking in C++. Ask the user to enter three numbers, one after each other. The numbers can be a decimal numbers (one or two decimal precision, such as 5.4 or 6.32) or integer between 0 and 10. Then find maximum of three numbers and message the user. Examples runs are given below. Example -1 Enter a number: 4.3 Enter a number: 0.5 Enter a number: 6.7 The max of three number: 6.7...
use matlab
To use the digits function, enter 1 To use the average function, enter 2 To use the perfect sum function, enter3 To exit the program, enter 4 Please select a number = 6 Please re-select again: 2 please enter the first number 3 please enter the second number: 6 please enter the third number: 3 The average equals to: 4 Write a function, called digits function that is able to calculate the number of digits and the summation...
build a phone number from digits entered by your user. Your program will loop until 10 valid digits have been entered. It will then use those digits to display the phone number entered using the format: XXXXXXXXXX (or (XXX) XXX – XXXX for extra credit). The program will ask for a digit, it will check to see if the digit is actually between 0 and 9 inclusively. If so, the digit will be stored as the next number in the...