Question

In: Computer Science

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

Solutions

Expert Solution

There are many errors. I am going to list them down 1 by 1.

1. Main method should be public not private.

2. string class in java has a capital S. So it is String not string.

3. double quotes in starting are not correct quotes. and the value of string should also end with double quotes.

4. To print something we use System class not Sytem class.

5. Java is case sensitive so Msg and msg are not same, so we need to change one of those. I am changing the line String msg = "Hello, Wrld!";

6. starting quote before Ken is not correct.

7. Semicolon missing in the println statement at the end.

8. Closing bracket of main method and class are missing, so we need to add two closing brackets.

9. Main method should not return anything. it should return void.

Below is the correct code:

public class Hello {

        public static void main(String[] args) {

                String msg = "Hello, Wrld!";

                System.out.println(msg + "Ken");
        }
}

Output


Related Solutions

Can you fix the errors in this code? import java.util.Scanner; public class Errors6 {    public...
Can you fix the errors in this code? import java.util.Scanner; public class Errors6 {    public static void main(String[] args) {        System.out.println("This program will ask the user for three sets of two numbers and will calculate the average of each set.");        Scanner input = new Scanner(System.in);        int n1, n2;        System.out.print("Please enter the first number: ");        n1 = input.nextInt();        System.out.print("Please enter the second number: ");        n2 =...
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;...
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 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...
For each of the following Visual Basic code snippets, identify the syntax error.   If intX >...
For each of the following Visual Basic code snippets, identify the syntax error.   If intX > 100   lblResult.Text = "Invalid Data" End If   Dim str As String = "Hello" Dim intLength As Integer intLength = Length(str) If intZ < 10 Then   lblResult.Text = "Invalid Data"   Dim str As String = "123" If str.IsNumeric Then   lblResult.Text = "It is a number." End If   Select Case intX   Case < 0     lblResult.Text = "Value too low."   Case > 100     lblResult.Text = "Value too high."   Case Else     lblResult.Text = "Value...
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....
In this program, there are 3 bugs and 2 syntax errors. Please identify them! The source...
In this program, there are 3 bugs and 2 syntax errors. Please identify them! The source code is below. The source code is in C: /*------------------------------------------------------------------ File:  CylinderVolume.c  (Lab 3) Author: Gilbert Arbez, Fall 2018 Description: Calculates how the volume changes for different depths               in a horizontal cylinder. ------------------------------------------------------------------*/ #include <stdio.h> #include <stdlib.h> #include <math.h> // Define symbolic constant #define N       50    // number of points to compute #define TRUE    1 #define FALSE   0 // Prototypes void computeDisplayVolume(double, double); /*-------------------------------------------------------------------- Function: main Description:  Gets from the user...
Can you fix my code and remove the errors? Thank you!! ^^ ////////////////////////////////////////////////////////////////////////////////////////////////////// public class StackException<T,...
Can you fix my code and remove the errors? Thank you!! ^^ ////////////////////////////////////////////////////////////////////////////////////////////////////// public class StackException<T, size> extends Throwable { private final T[] S = null ; public StackException(String s) { } public T top() throws StackException { if (isEmpty()) throw new StackException("Stack is empty."); int top = 0; return S[top]; } private boolean isEmpty() { return false; } public T pop() throws StackException { T item; if (isEmpty()) throw new StackException("Stack underflow."); int top = 0; item = S[top];...
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...
GIVEN THE CODE BELOW Given the following class: /** * Document class. */ public class Document...
GIVEN THE CODE BELOW Given the following class: /** * Document class. */ public class Document { private int words; /** * constructor * pre: none * post: A Document object created. Words initialized to 0. */ public Document() { words = 0; //default words } /** * Changes the number of document words. * pre: none * post: Words has been changed. */ public void setWords(int numWords) { words = numWords; } /** * Calculates the number of pages....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT