You will write a program that will read a number from the user. You may use either the Scanner of the BufferedReader. You will verify that the number is indeed a number (use try/catch), if it is not a number you will end the program. If it is a number then you will verify that is a positive integer in the range from 1 to 9 (inclusive). If the number is not in range you will end the program. If the number is in range you will print the number itself as many times as the number. You MUST use a looping structure, either for, while or do loops. Example: If the user enters the number 6, the output of your program should be.
666666
/* Here is your required code*/
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.print("Enter number in range(1-9)");
String n=sc.next();
try{
Integer.parseInt(n);
int m=Integer.parseInt(n);
if(m>0&&m<10)
{
for(int i=0;i<m;i++)
System.out.print(m);
}
else
System.out.print("Number not in range(1-9)");
}
catch(NumberFormatException ex){
System.out.println("Input is not
number");
}
}
}
You will write a program that will read a number from the user. You may use...
Write a program which asks the user to enter an integer. Use switch statement to write out the numeric word (such as ONE) if the user's input is 1; (see the sample run output for the usr input 2 or 3); otherwise, write OUT OF RANGE. Below are few sample runs: If the user enters a 1, the program will print: ONE TWO THREE Or, if the user enters a 2, the program will print: TWO THREE Or, if the...
I need this code in Java! Start by read in a number from the user that is in the range 1-200. If the user inputs a number out of that range, print out: Invalid number, and end the program. Next, If a number is divisible by 3, print Fizz instead If a number is divisible by 5, print Buzz instead If a number is divisible by both 3 and 5, print out FizzBuzz If a number is none of the...
Write a c++ complete program to meet the specifications. The program should prompt the user for a positive integer. The program should print a message whether the integer is even or odd. The looping should end when the user enters a negative number. The negative number will not be tested for even or odd. The program will print out a message of how many numbers were entered (not counting the negative number) and how many even and odd numbers were...
5.2 Write a program that repeatedly prompts a user for integer numbers until the user enters 'done'. Once 'done' is entered, print out the largest and smallest of the numbers. If the user enters anything other than a valid number catch it with a try/except and put out an appropriate message and ignore the number. Enter 7, 2, bob, 10, and 4 and match the output below. 1 largest = None 2 smallest = None 3 while True: 4...
5.2 Write a program that repeatedly prompts a user for integer numbers until the user enters 'done'. Once 'done' is entered, print out the largest and smallest of the numbers. If the user enters anything other than a valid number catch it with a try/except and put out an appropriate message and ignore the number. Enter 7, 2, bob, 10, and 4 and match the output below. 1 largest = None 2 smallest = None 3 while True: 4 num...
In C++ Programming, Try using loops only. This lab demonstrates the use of the While Loop and the Do While Loop as error checking mechanisms. You will be using each of these loops to solve the same problem. Please put them both in the same program. When you test the code, you will not see a difference in the way they execute - but there will be a difference in the logic when writing the code. You will want to...
Introduction: In this lab, you will write a MIPS program to read in (up to) 50 integer values from the user, store them in an array, print out the amay, one number per line, reverse the elements in the array and finally print out the elements in the just-reversed) array. Feel free to do this lab and all assembly programming labs) in Windows. You must use MARS Getting started: l. In MARS, create a new assembly file with the name...
Write a program that (in the main program) prompts the user for the (integer) model number of their car. The main function should then call the function check defective which should • take in the model number of the car • check if the model number is 119, 179, 221, 780, or anything between 189 and 195, inclusive, which indicates the car is defective • print a message indicating whether or not the car is defective Note: this is should...
Write a C++ program using "for" loop to allow user to guess a certain number say 55. The loop will end after 5 guesses or if he guesses the right number, which ever comes first. If user enters a number greater than 55, your program should print "You entered a bigger number". If user enters a number smaller than 55, your program should print "You entered a smaller number". If user enters 55 in less than 5 attempt, your program...
Part 1: Read 2 numbers from the user. One small number and one big number for the range. Use this in a for loop with range (for x in range(small, big)) Add all the numbers in this range and store in a variable called total. Print total. Part 2: Make a list of colors called COLORS. Have at least 10 colors. Read one color from the user in a variable called color. Now use a for loop, and see if...