Unendliche While-Schleife in Java

Hey there! Ich bin versucht zu tun, einige Daten, die Validierung von Eingaben, aber ich habe nicht in der Lage, um es herauszufinden. Ich bin immer eine unendliche while-Schleife, wenn ich versuchen, zu überprüfen, ob das erste Zeichen eingegeben haben, ist ein Brief. . . .

Vielen Dank für Ihre Hilfe!

public class methods
{
    public static void main(String args[]) throws IOException
    {
        String input ="";
        int qoh=0;
        boolean error=true;

        Scanner keyboard = new Scanner (System.in);

        //while (error)
        //{
            //error=true;

        while (error==true)
        {
           System.out.print("\nEnter Quantity on Hand: ");
           input = keyboard.nextLine();

           if (input.length() <1)
           {
               System.out.println("\n**ERROR06** - Quantity on hand must be between 0 and 500");
               error=true;
               System.out.println(qoh);
               System.out.println(input);
            }
            else
            {
                error=false;
            }
        }

        error = true;

        while (error==true)
        {
            if (Character.isLetter(input.charAt(0)))
            {
                System.out.println("\n**ERROR06** - Quantity on hand must be between 0 and 500");
                error=true;
                System.out.println(qoh);
                System.out.println(input);
             }
             else
             {
                 qoh = Integer.parseInt(input);
                 error=false;
              }
          }
      }
  }
Randnotiz: while(Fehler == true) kann geschrieben werden als, während(Fehler)

InformationsquelleAutor Andy | 2010-02-26

Schreibe einen Kommentar