Question

Inspect the following code for syntax errors, correct the error by stating the line number and...

Inspect the following code for syntax errors, correct the error by stating the line number and re-write the line of code involved. You do not have to re-write the entire program. There are six errors.

1 import java.lang.Scanner;

2

3 public class PositiveNegative

4 {

5 public static main(String [] args)

6 {

7 double number = 0;

8

9 Scanner input = new Scanner(system.in);

10

11 System.out.print("Enter a number ==> ");

12 number = input.nextDouble()

13

14 if (number < 0) then

15 System.out.println("Negative ");

16 else

17 System.out.println("Positive");

18 )

19 }

0 0
Add a comment Improve this question Transcribed image text
Answer #1
import java.util.Scanner;   // change lang to util

public class PositiveNegative {

    public static void main(String[] args) {    // add void here
        double number = 0;
        Scanner input = new Scanner(System.in); // use System instead of system
        System.out.print("Enter a number ==> ");
        number = input.nextDouble();    // end statement with ;
        if (number < 0)     // remove then here
            System.out.println("Negative ");
        else
            System.out.println("Positive");
    }// replace ) with }
}

Add a comment
Know the answer?
Add Answer to:
Inspect the following code for syntax errors, correct the error by stating the line number and...
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
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