Question

In: Computer Science

There is error in this java code. Pls debug. // Prompt user for value to start...

There is error in this java code. Pls debug.

// Prompt user for value to start
// Value must be between 1 and 20 inclusive
// At command line, count down to blastoff
// With a brief pause between each displayed value
import java.util.*;
public class DebugSix3
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
String userNumString;
int userNum, val;
final int MIN = 1;
final int MAX = 20;
System.out.println("Enter a number between " + MIN + " and " + MAX + " inclusive");
userNumString = input.next();
userNum = Interger.parseInt(userNumString);
while(userNum < MIN || userNum = MAX)
{
System.out.println("Number out of range" +
"\nEnter a number between " + MIN + " and " + MAX + " inclusive");
userNumString = input.next();
userNum = Integer.parse(userNumString);
}
for(val = userNum; val < 0; --val)
{
System.out.print(val + " ");
for(int x = 0; x < 100000; ++x)
for(int y = 0; y < 10000; ++y);
// Adjust these numbers for faster or slower performance
}
System.out.println("Blastoff!");
}
}


Solutions

Expert Solution

// Prompt user for value to start
// Value must be between 1 and 20 inclusive
// At command line, count down to blastoff
// With a brief pause between each displayed value
import java.util.*;
public class DebugSix3
{
  public static void main(String[] args)
  {
    Scanner input = new Scanner(System.in);
    String userNumString;
    int userNum, val;
    final int MIN = 1;
    final int MAX = 20;
    System.out.println("Enter a number between " + MIN + " and " + MAX + " inclusive");
    userNumString = input.next();
    userNum = Integer.parseInt(userNumString);
    while(userNum < MIN || userNum > MAX)
    {
      System.out.println("Number out of range" +
        "\nEnter a number between " + MIN + " and " + MAX + " inclusive");
      userNumString = input.next();
      userNum = Integer.parseInt(userNumString);
    }
    for(val = userNum; val >= 0; --val)
    {
      System.out.print(val + " ");
      for(int x = 0; x < 100000; ++x)
        for(int y = 0; y < 10000; ++y);
// Adjust these numbers for faster or slower performance
    }
    System.out.println("Blastoff!");
  }
}


Related Solutions

Write an error-free Java program to do the following things. Prompt the user to input a...
Write an error-free Java program to do the following things. Prompt the user to input a set of numbers. The numbers represent hourly wages so they will be between 7.25 (peon) and 50 (big boss). The user should be able to input up to 35 numbers but if the user enters 0 then the data input ceases. All of the data that the user enters should be stored in a single array. You do not need to check the input...
I need a java code Write a simple program to prompt the user for a number...
I need a java code Write a simple program to prompt the user for a number between 1 and 12 (inclusive) and print out the corresponding month. For example:   The 12th month is December. Use a java "switch" statement to convert from the number (1-12) to the month. Also use a "do while" loop and conditional checking to validate that the number entered is between 1 and 12 inclusive and if not, prompt the user again until getting the correct...
Write a java code snippet to prompt the user for the number of names they’d like...
Write a java code snippet to prompt the user for the number of names they’d like to enter. Create a new array of the size chosen by the user and prompt the user for each of the names. Output the list of names in reverse order.
Code in Java Change the instructionLabel to ask the user to enter a numeric value into...
Code in Java Change the instructionLabel to ask the user to enter a numeric value into the textField and click the button to convert the entered value from kilometers to miles (1.609344 km = 1 mile). When the actionButton on the form is clicked, ActionWindow should take the value entered in the textField, convert it from kilometers to miles, and display the result in the resultField. import java.awt.Container; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; public class...
Create in Java a program that will prompt the user to enter aweight for a...
Create in Java a program that will prompt the user to enter a weight for a patient in kilograms and that calculates both bolus and infusion rates based on weight of patient in an interactive GUI application, label it AMI Calculator. The patients weight will be the only entry from the user. Use 3999 as a standard for calculating BOLUS: To calculate the BOLUS you will multiply 60 times the weight of the patient for a total number. IF the...
Create in java a program that will prompt the user to enter a weight for a...
Create in java a program that will prompt the user to enter a weight for a patient in kilograms and that calculates infusion rates based on weight of patient in an interactive GUI application, label it HEPCALC. The patients’ weight will be the only entry from the user. To calculate the infusion rate you will multiply 12 times the weight divided by 50 for a total number. The end result will need to round up or down the whole number....
IN JAVA PROGRAMMING Write a complete Java program to do the following: a) Prompt the user...
IN JAVA PROGRAMMING Write a complete Java program to do the following: a) Prompt the user to enter the name of the month he/she was born in (example: September). b) Prompt the user to enter his/her weight in pounds (example: 145.75). c) Prompt the user to enter his/her height in feet (example: 6.5). d) Display (print) a line of message on the screen that reads as follows: You were born in the month of September and weigh 145.75 lbs. and...
IN JAVA PROGRAMMING Write a complete Java program to do the following: a) Prompt the user...
IN JAVA PROGRAMMING Write a complete Java program to do the following: a) Prompt the user to enter a six-digit integer. b) Take the integer and break it up into two pieces of three-digits each (make sure you keep the order of digits). c) Display each 3-digit piece on a separate line with a proper message before each piece. For example, if the user enters  450835 as the integer, then the program should display the following output: Right 3-digit piece: 835...
This code needs to be in C++, please. Step 1: Add code to prompt the user...
This code needs to be in C++, please. Step 1: Add code to prompt the user to enter the name of the room that they are entering information for. Validate the input of the name of the room so that an error is shown if the user does not enter a name for the room. The user must be given an unlimited amount of attempts to enter a name for the room. Step 2: Add Input Validation to the code...
Write by hand a full java program that will prompt the user for the length and...
Write by hand a full java program that will prompt the user for the length and width of a square, calculate and display the area of that square rounded to the nearest tenth with an appropriate message.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT