Question

In: Computer Science

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.

Please Fix code and make Copy/Paste avaliable

// Application allows user to enter a series of words

// and displays them in reverse order

import java.util.*;

public class DebugEight4

{

   public static void main(String[] args)

   {

      Scanner input = new Scanner(System.in);

      int x = 0, y = 0;

      String array[] = new String[100];

      String entry;

      final String STOP = "STOP";

      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);

}

}

Solutions

Expert Solution

Explanation:

Two logical errors were there in the for loop, written at the last.

1) y should start from x-1 and keep decrementing by 1 every time, it was getting incrementing instead.

2) In the condition of the for loop, index 0 should also be covered, so, y>=0 is the right condition

Correct code:

import java.util.*;

public class DebugEight4

{

public static void main(String[] args)

{

Scanner input = new Scanner(System.in);

int x = 0, y = 0;

String array[] = new String[100];

String entry;

final String STOP = "STOP";

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);

}

}

Output:

PLEASE UPVOTE IF YOU FOUND THIS HELPFUL!
PLEASE COMMENT IF YOU NEED ANY HELP!


Related Solutions

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. DebugBox.java public class DebugBox { private int width; private int length; private int height; public DebugBox() { length = 1; width = 1; height = 1; } public DebugBox(int width, int length, height) { width = width; length = length; height =...
The following code segment which uses pointers may contain logic and syntax errors. Find and correct...
The following code segment which uses pointers may contain logic and syntax errors. Find and correct them. a) Returns the sum of all the elements in summands int sum(int* values) { int sum = 0; for (int i = 0; i < sizeof(values); i++) sum += *(values + i); return sum; } b) Overwrites an input string src with "61C is awesome!" if there's room. Does nothing if there is not. Assume that length correctly represents the length of src....
Each of the following files in the Chapter15 folder of your downloadable student files has syntax and/or logic errors.
Each of the following files in the Chapter15 folder of your downloadable student files has syntax and/or logic errors. In each case, determine the problem and fix the program. After you correct the errors, save each file using the same filename preceded with Fix. For example, DebugFifteen1.java will become FixDebugFifteen1.java. a. DebugFifteen1.java b. DebugFifteen2.java c. DebugFifteen3.java d. DebugFifteen4.java    
identify the syntax errors in the following code:             public class Hello {                    &
identify the syntax errors in the following code:             public class Hello {                         private static int main(String [] args) {                                     string Msg=”Hello, Wrld!;                                     Sytem.out.println(msg+ “Ken")
To earn full credit, program must be free of syntax, run-time, and logic errors; include program...
To earn full credit, program must be free of syntax, run-time, and logic errors; include program comments; use reasonable readable variable names and prompts. To include variables in the input prompt, you must use concatenation character (+). For example: assume you already asked for input of employee's first name and last name (they are stored into variables FirstName and LastName, then use this prompt to ask for employee's weekly hours which includes the employee's full name in the input statement....
Please use C++. You will be provided with two files. The first file (accounts.txt) will contain...
Please use C++. You will be provided with two files. The first file (accounts.txt) will contain account numbers (10 digits) along with the account type (L:Loan and S:Savings) and their current balance. The second file (transactions.txt) will contain transactions on the accounts. It will specifically include the account number, an indication if it is a withdrawal/deposit and an amount. Both files will be pipe delimited (|) and their format will be the following: accounts.txt : File with bank account info...
***The code is provided below*** When trying to compile the code below, I'm receiving three errors....
***The code is provided below*** When trying to compile the code below, I'm receiving three errors. Can I get some assistance on correcting the issues? I removed the code because I thought I corrected my problem. I used #define to get rid of the CRT errors, and included an int at main(). The code compiles but still does not run properly. When entering the insertion prompt for the call details, after entering the phone number, the program just continuously runs,...
Part 1: Find and fix errors and add following functionalities 1. There are several syntax errors...
Part 1: Find and fix errors and add following functionalities 1. There are several syntax errors in the code that are preventing this calculator from working, find and fix those errors. When they are fixed, the number buttons will all work, as well as the + (add) and -- (decrement) buttons. a. To find the errors, open up the Developers Tool of the browser and look at the console (F12). Verify the add functionality works. For a binary operator, you...
There are two errors in this code. Identify the errors and give the correct code that...
There are two errors in this code. Identify the errors and give the correct code that will make the program to display the following output: Rectangle: height 2.0 width 4.0 Area of the Rectangle is 8.0 ----- public interface Shape { public double getArea(); } class Rectangle implements Shape { double height; double width; public Rectangle(double height, double width) { this.height=height; this.width=width; } public double getArea() { return height*width; } public String toString() { return "Rectangle: height "+height+" width "+width;...
Quality assurance department of software house reveals that 6.5% of programming code contain logical errors. Quality...
Quality assurance department of software house reveals that 6.5% of programming code contain logical errors. Quality check software is developed to analyze code and in a test, identifies the error in 90% of the code with errors and 5% of those without. If code is marked by the program as possibly having a logical error, what is the probability that the code DOES have an error?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT