Write a an application Arithmetic which gets input from the user. It will have a
ID: 3843274 • Letter: W
Question
Write a an application Arithmetic which gets input from the user. It will have a main method. You will write the whole class Prompt the user for his/her name (it may be more than 1 word.) Use this prompt: System.out.print("What is your name? "); Read the name. Prompt the user for an integer. Use this prompt: System.out.print("Enter an integer: "); Read the integer. On one line: print the user name, " that's a " (notice the spaces), and one of the statements based on the following: Integer is less than 0, print "small number" Integer is greater than or equal to 0 and less than or equal to 10000, print "middle-sized number" If the integer is anything else, print "big number" Reminders: Remember the difference between next and nextLine Use the appropriate if / else if / else statements Do not do unnecessary tests
WRITE THE CODE IN JAVA
Explanation / Answer
import java.util.Scanner;
public class Arithmetic {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
System.out.print("What is your name? ");
String name = s.nextLine();
System.out.print("Enter an integer: ");
int number=s.nextInt();
System.out.print(name + " ");
if (number<0)
{
System.out.print("small number");
}
else if ((number>0 || number==0) && (number<10000 || number==10000))
{
System.out.print("middle-sized number");
}
else
{
System.out.print("big number");
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.