What message will the following program display if the user enters 5? What if the user enters 10? What if the user enters 100?
import javax.swing.J0ptionPane;
public class Checkpoint
{
public static void main(String[ ] args)
{
String input;
int number;
input = JOptionPane.showInputDialog(“Enter a number.”);
number = Integer.parseInt(input);
if (number < 10)
method1();
else
method2();
System.exit(0);
}
public static void method1()
{
J0ptionPane.showMessageDialog(nul1, “Able was I.”);
}
public static void method2()
{
J0ptionPane.showMessageDialog(null, “I saw Elba.”);
}
}
Want to see the full answer?
Check out a sample textbook solutionChapter 5 Solutions
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
Additional Engineering Textbook Solutions
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
Electric Circuits. (11th Edition)
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
Starting Out with C++ from Control Structures to Objects (9th Edition)
Java: An Introduction to Problem Solving and Programming (8th Edition)
- // Displays five random numbers between // (and including) user-specified values import java.util.Scanner; public class DebugSix4 { public static void main(String[] args) { int high, low, count = 0; final int NUM = 5; Scanner input = new Scanner(System.in); System.out.print("This application displays " + NUM + " random numbers" + "\nbetween the low and high values you enter" + "\nEnter low value now... "); low = input.nextInt() System.out.print("Enter high value... "); high = inputnextInt(); while(low < high) { System.out.println("The number you entered for a high number, " + high + ", is not more than " + low); System.out.print("Enter a number higher than " + low + "... "); high = input.nextInt(); while(count < NUM) { double result = Math.random(); int answer = (int) (result * 10 + low); if(answer <=…arrow_forwardclass Output{public static void main(String args[]){Integer i = new Integer(557);float x = i.floatValue();System.out.print(x);}} What will the given code prints on the output screen.arrow_forwardThis is the code that needs to be corrected: // This application gets a user's name and displays a greeting import java.util.Scanner; public class DebugThree3 { public static void main(String args[]) { String name; name = getName(); displayGreeting(name); } public static String getName(name) { String name; Scanner input = new Scanner(System.in); System.out.print("Enter name "); name = input.nexlLine(); return name; } public static displayGreeting(String name) { System.outprintln("Hello, " + name + "!"); } }arrow_forward
- answer itarrow_forwardPrint "userNum1 is negative." if userNum1 is less than 0. End with newline. Assign userNum2 with 4 if userNum2 is greater than 9. Otherwise, print "userNum2 is less than or equal to 9.". End with newline. 1 import java.util.Scanner; 2 public class UserNums { public static void main (String [] args) { int userNum1; int userNum2; 4 6. 7 Scanner input userNum1 = 8. = new Scanner(System.in); input.nextInt(); input.nextInt(); 9. 10 userNum2 11 12 V* Your code goes here */ 13 System.out.println("userNum2 is " } 14 + userNum2); 15 16 17 }arrow_forwardJAva Input. class increment { public static void main(String args[]) { double var1 = 1 + 5; double var2 = var1 / 4; int var3 = 1 + 5; int var4 = var3 / 4; System.out.print(var2 + " " + var4); } } Find output.arrow_forward
- Input class Output { public static void main(String args[]) { int x , y = 1; x = 10; if (x != 10 && x / 0 == 0) System.out.println(y); else System.out.println(++y); } } Find outputarrow_forwardpublic void foo4() { String s2 = "smith"; String s3 = s2; String s4 = null; String s5 = ""; String só = new String(s2); if(s2 == s3) { System.out.print("1"); } if(s2.equals(s3)) { System.out.print("2"); } if(s2 == s6) { System.out.print("3"); } if(s2.equals(s6)) { System.out.print("4"); } if(s5 == s4) { System.out.print("5"); } if(s4.equals(s5)) { System.out.print("6"); } 3//end of foo4() Examine and trace the method foo4() above, which statement IS true? O The method will print out "356" on screen. The method will print out "1234" on screen. The method will print out "123" on screen. The method will print out "124" on screen.arrow_forwardimport javax.swing.JOptionPane; public class Mileage { public static void main(String[] args) { String inputString; double miles; double gallons; double mpg; inputString= JOptionPane.showInputDialog("This program will calculate mileage"); miles =Double.parseDouble(inputString); inputString= JOptionPane.showInputDialog("Enter amount of miles driven:"); gallons =Double.parseDouble(inputString); mpg= (miles/gallons); JOptionPane.showMessageDialog(null, "Miles per gallon: "+ mpg); System.exit(0); }} hi, I will like to know how can I display the result "mpg", but with 2 decimals? What or how should I add to my code? Also how would you explain your addition in pseudo-code?arrow_forward
- // Program prompts user to enter a series of integers // separated by spaces // Program converts them to numbers and sums them import java.util.*; public class DebugSeven2 { publicstaticvoidmain(String[] args) { String str; int x; int length; int start; int num; int lastSpace =-1; int sum =0; String partStr; Scanner in =newScanner(System.in); System.out.print("Enter a series of integers separated by spaces >> "); str = in.nextLine; length = str.length(); for(x =0; x <= length; ++x) { if(str.charAt(x) ==' ') { partStr = str.substring(lastSpace + 1, y); num = Integer.parseInt(partStr); System.out.println(" " + num); sum += number; lastSpace = x; } } partStr = str.substring(lastSpace + 1, length); num = Integer.parseInt(partStr); System.out.println(" " + num); sum += num; System.out.println(" -------------------" + "\nThe sum of the integers is "+ sum); } }arrow_forward// Application allows user to enter a series of words // and displays them in reverse order import java.util.*; public class DebugEight4 { publicstaticvoidmain(String[] args) { Scanner input =newScanner(System.in); int x =0, y; String array[] =newString[100]; String entry; finalString STOP =XXX; StringBuffer message =new StringBuffer("The words in reverse order are\n"); System.out.println("Enter any word\n" + "Enter + STOP + when you want to stop"); entry = input.next(); while(!(entry.equals(STOP))) { array[x] = entry; ++x; System.out.println("Enter another word\n" + "Enter "+STOP+" when you want to stop"); entry = input.next(); } for(y = x -1; y >0; ++y) { message.append(array[y]); message.append("\n"); } System.out.println(message) }arrow_forwardForms often allow a user to enter an integer. Write a program that takes in a string representing an integer as input, and outputs Yes if every character is a digit 0-9. Ex: If the input is: 1995 the output is: Yes Ex: If the input is: 42,000 or 1995! the output is: No Hint: Use a loop and the Character.isDigit() function.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education