operator < nicht angewendet werden kann, um java

Da unten habe ich eingegeben javac App.java auf mac-Terminal und ich sehe Betreiber fünf Fehler, alle sind gleich. Ich bin mir nicht sicher, wie es zu lösen ist als unten, und ich Schätze Ihre Hinweise?

Habe ich importieren javabook.*; und das ist JAVA-code auf Textpad.

import javabook.*;              
//import java.util.Scanner;         

class App
{
    public static void main(String args[])
    {


        //declare variable
        String theNumber;

        //declare object
        Scanner someInput;

        //input
        System.out.println("Please enter area size : ");
        someInput = new Scanner(System.in);
        theNumber = someInput.nextLine();

        //processing

        if ( theNumber < 20 )
        {
            System.out.println( "It is too small." ) ;
        }
        else if ( theNumber > 20 && theNumber < 40 )
        {
            System.out.println( "It is perfect size." ) ;
        }

        else if ( theNumber > 40 && theNumber < 60 )
        {
            System.out.println( "It is too big." ) ;
        }

        //close the program without error
        System.exit(0);
    }
}

Terminal response als App.java:28: operator < nicht angewandt werden kann java.lang.String,int
if ( Zahl < 20 )

Ich würde Ihre Hilfe schätzen?

AKTUALISIERT:

import javabook.*;              //Same result Scanner or javabook. Tried both and it worked.
import java.util.Scanner;       //this is required

class App
{
    public static void main(String args[])
    {


        //declare variable
        //String theNumber;
        //int theNumber = Integer.parseInt(someInput.nextLine());

        int theNumber; //need to convert your string theNumber to an int first. If you search for that, you'll find lots, both here and on the internet generally.
        int a = Integer.parseInt(theNumber);
        //theNumber = someInput.nextInt(); //this is commented out so now down to two errors

        //declare object
        Scanner someInput;

        //input
        System.out.println("Please enter area size : ");
        someInput = new Scanner(System.in);
        theNumber = someInput.nextLine();

        //processing

        if ( theNumber < 20 )
        {
            System.out.println( "It is too small." ) ;
        }
        else if ( theNumber > 20 && theNumber < 40 )
        {
            System.out.println( "It is perfect size." ) ;
        }

        else if ( theNumber > 40 && theNumber < 60 )
        {
            System.out.println( "It is too big." ) ;
        }

        //close the program without error
        System.exit(0);
    }
}
"string" < 42 ist ungültig (theNumber ist ein String variable).
Genau so, wie Sie es sagt: Wie vergleichst du einen string, wie abdskjh mit 20?? Sie transformieren müssen Ihre Zeichenkette in eine Zahl, geben Sie zuerst (ein int oder double zum Beispiel).
Danke für Eure Antworten. Wie kann ich es beheben?
Sorry, ein versehen, das jetzt entfernt.
es konnte fehlschlagen, wenn der Benutzer etwas anderes als ein int.

InformationsquelleAutor Irishgirl | 2013-05-22

Schreibe einen Kommentar