Question:

What is wrong with this java program? Will choose best answer!!!?

by  |  earlier

0 LIKES UnLike

This program is supposed to display which value is more.

<,>,=.

There are many errors called "<identifier> expected" and "illegal start of type". What do these mean and how do I fix them?

import java.util.Scanner;

class GreaterThanLessThanOrEqualTo {

public static void main(String args[]);

Scanner myScanner = new Scanner(System.in);

double 1stNumber;

double 2ndNumber;

System.out.print("1st Number= ");

1stNumber = myScanner.nextDouble();

System.out.print("2nd Number= ");

2ndNumber = myScanner.nextDouble();

if (1stNumber == 2ndNumber) {

System.out.print(1stNumber);

System.out.print("=");

System.out.print(2ndNumber);

}

if (1stNumber > 2ndNumber) {

Sysetm.out.print(1stNumber);

System.out.print(">");

System.out.print(2ndNumber);

}

if (1stNumber < 2ndNumber) {

System.out.print(1stNumber);

System.out.print("<");

System.out.print(2ndNumber);

}

}

 Tags:

   Report

2 ANSWERS


  1. public static void main(String args[]); that is not the correct way to define a funnction.


  2. First of all, there&#039;s an error in your &quot;main&quot;. You need brackets even if you are not going to use it.

    public static void main(String args[])

    {

    }

    Secondly, don&#039;t use numbers as your variable.

    double firstNumber;

    double secondNumber;

    Third there&#039;s a typo in your second IF statement. You typed &quot;Sysetm&quot; instead of &quot;System&quot;.

    Fourth, your statements are not contained within a method. They are now floating around without a valid container to hold them. Move all those chunks of validation into the main and see that it works fine.

    import java.util.Scanner;

    class GreaterThanLessThanOrEqualTo {



    public static void main(String args[])

    {

    Scanner myScanner = new Scanner(System.in);



    double stNumber;

    double ndNumber;

    System.out.print(&quot;1st Number= &quot;);

    stNumber = myScanner.nextDouble();

    System.out.print(&quot;2nd Number= &quot;);

    ndNumber = myScanner.nextDouble();

    if (stNumber == ndNumber) {

    System.out.print(stNumber);

    System.out.print(&quot;=&quot;);

    System.out.print(ndNumber);

    }

    if (stNumber &gt; ndNumber) {

    System.out.print(stNumber);

    System.out.print(&quot;&gt;&quot;);

    System.out.print(ndNumber);

    }

    if (stNumber &lt; ndNumber) {

    System.out.print(stNumber);

    System.out.print(&quot;&lt;&quot;);

    System.out.print(ndNumber);

    }

    }

    }

Question Stats

Latest activity: earlier.
This question has 2 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.
Unanswered Questions