Question

The files provided in the code editor to the right contain syntax and/or logic errors. In...

The files provided in the code editor to the right contain syntax and/or logic errors. In each case, determine and fix the problem, remove all syntax and coding errors, and run the program to ensure it works properly.

// 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!");
}
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

// 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 + " ");

            try{

                // sleep for 1 second

                Thread.sleep(1000);

            }

            catch(InterruptedException e){

                e.printStackTrace();

            }

            // Adjust these numbers for faster or slower performance

        }

        System.out.println("\nBlastoff!");

    }

}


Sample Output

Add a comment
Know the answer?
Add Answer to:
The files provided in the code editor to the right contain syntax and/or logic errors. In...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The files provided in the code editor to the right contain syntax and/or logic errors. In...

    The files provided in the code editor to the right contain syntax and/or logic errors. In each case, determine and fix the problem, remove all syntax and coding errors, and run the program to ensure it works properly. // DebugFive2.java // Decides if two numbers are evenly divisible import java.util.Scanner; public class DebugFive2 { public static void main(String args[]) { int num; int num2; Scanner input = new Scanner(System.in); System.out.print("Enter a number "); num = input.nextInteger() System.out.print("Enter another number ");...

  • The files provided contain syntax and/or logic errors. In each case, determine and fix the problem,...

    The files provided contain syntax and/or logic errors. In each case, determine and fix the problem, remove all syntax and coding errors, and run the program to ensure it works properly. import java.util.*; public class DebugEight1 { public static void main(String args[]) { Scanner input = new Scanner(System.in); char userCode; String entry, message; boolean found = false; char[] okayCodes = {'A''C''T''H'}; StringBuffer prompt = new StringBuffer("Enter shipping code for this delivery\nValid codes are: "); for(int x = 0; x <...

  • The files provided in the code editor to the right contain syntax and/or logic errors. In...

    The files provided in the code editor to the right contain syntax and/or logic errors. In each case, determine and fix the problem, remove all syntax and coding errors, and run the program to ensure it works properly. // Start with a penny // double it every day // how much do you have in a 30-day month? public class DebugSix1 { public static void main(String args[]) { final int DAYS = 30; double money = 0.01; int day =...

  • This is a JAVA language The files provided in the code editor to the right contain...

    This is a JAVA language The files provided in the code editor to the right contain syntax and/or logic errors. In each case, determine and fix the problem, remove all syntax and coding errors, and run the program to ensure it works properly. Note: DebugData2.txt does not need to be edited. It is used by the program. DebugData2.txt 435-9845 239-9845 981-9883 384-5656 875-3784 874-8120 DebugThirteen2.java // Program reads in a file of phone numbers without area codes // inserts "(312)...

  • Correct the five syntax, run-time or logic errors that are found in the CountAndAverageNumbers.java file. Link...

    Correct the five syntax, run-time or logic errors that are found in the CountAndAverageNumbers.java file. Link to the file: CountAndAverageNumbers.javaPreview the document. Make sure you include comments in your code where errors were corrected. If you do not flag each error with a comment, points will be deducted. Upload the corrected .java file here. The output of the corrected file looks like the following: Debug4Output.PNG This program reads an unspecified number of integers, determines how many positive and negative values...

  • I am given an input file, P1input.txt and I have to write code to find the...

    I am given an input file, P1input.txt and I have to write code to find the min and max, as well as prime and perfect numbers from the input file. P1input.txt contains a hundred integers. Why doesn't my code compile properly to show me all the numbers? It just stops and displays usage: C:\> java Project1 P1input.txt 1 30 import java.io.*; // BufferedReader import java.util.*; // Scanner to read from a text file public class Project1 {    public static...

  • Write four overloaded methods called randomize. Each method will return a random number based on the...

    Write four overloaded methods called randomize. Each method will return a random number based on the parameters that it receives: randomize() - Returns a random int between min and max inclusive. Must have two int parameters. randomize() - Returns a random int between 0 and max inclusive. Must have one int parameter. randomize() - Returns a random double between min and max. Must have two double parameters. randomize() - Returns a random double between 0 and max. Must have one...

  • Write an application that displays a series of at least five student ID numbers (that you...

    Write an application that displays a series of at least five student ID numbers (that you have stored in an array) and asks the user to enter a numeric test score for the student. Create a ScoreException class, and throw a ScoreException for the class if the user does not enter a valid score (less than or equal to 100). Catch the ScoreException, display the message Score over 100, and then store a 0 for the student’s score. At the...

  • I need help asking the user to half the value of the displayed random number as...

    I need help asking the user to half the value of the displayed random number as well as storing each number generated by the program into another array list and displayed after the game is over at the end java.util.*; public class TestCode { public static void main(String[] args) { String choice = "Yes"; Random random = new Random(); Scanner scanner = new Scanner(System.in);    ArrayList<Integer> data = new ArrayList<Integer>(); int count = 0; while (!choice.equals("No")) { int randomInt =...

  • - Part 1 – 4 Debugging Exercises – there are things wrong – either logic or...

    - Part 1 – 4 Debugging Exercises – there are things wrong – either logic or syntax errors.  Correct the pseudocode and one Java program. Add the corrected code in BOLD and change the corrected color to RED.   Debugging 4:  Add the missing code in bold and red. import java.util.Scanner; public class Airline {             public static void main(String args[])             {                         Scanner s = new Scanner(System.in);                         String passengerName = ""                              String ageString = ""                           int passengerAge = 0                         System.out.println("Enter passenger's name: ");                         passengerName  =...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT