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

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...
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...
JAVA Write a java program that will sum all positive number. Prompt the user to enter...
JAVA Write a java program that will sum all positive number. Prompt the user to enter numbers and add all positive numbers. The program will not add negative numbers and the program will stop when you enter ‘0’.   Enter a number> 25 Enter a number> 9 Enter a number> 5 Enter a number> -3 Enter a number> 0 Sum = 39
Prompt the user for their name, get and store the user input. Prompt the user for...
Prompt the user for their name, get and store the user input. Prompt the user for their age, get and store the user input. We will assume that the user will enter a positive integer and will do no error checking for valid input. Determine and store a movie ticket price based on the user's age. If their age is 12 or under, the ticket price is $5. If their age is between 13 and 64, inclusive, the ticket price...
Using Java, write a program named MyAngles that will prompt the user for the measure of...
Using Java, write a program named MyAngles that will prompt the user for the measure of the three sides of a triangle and then reports the measurement of each interior angle of the triangle and the area of the triangle.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT