TWiki home XP > XP > ClasseEntradaFinal ( vs. r1.1) XP webs:
Main | TWiki | Sandbox | Portugues
XP . { Bugzilla Últimas atualizações Busca Registro Sobre o TWiki }
 <<O>>  Difference Topic ClasseEntradaFinal (r1.1 - 07 Jul 2005 - AndreGermanoRegert)
Line: 1 to 1
Added:
>
>
META TOPICPARENT TestesParaOJogoDoMeio
-- AndreGermanoRegert - 07 Jul 2005


/*
 * Created on 05/07/2005
 */
package Uteis;
/**
 * @author André Germano Regert
 *          Jader Wallauer
 */
public class Entrada {

   public String inString(){
      int aChar;
       String s = "";
       boolean finished = false;

       while(!finished){
          try   {
             aChar = System.in.read();
               if (aChar < 0 || (char)aChar == '\n')
                  finished = true;
               else if ((char)aChar != '\r')
            s = s + (char)aChar;   // Enter into string
           } catch(java.io.IOException e) {
            System.out.println("Input error");
             finished = true;
           }
       }
       return s;
   }

   public int inInt(){
      boolean finished = false;
      int retorno = 0;
      while(!finished){
         //inputFlush();
         //printPrompt(prompt);
         try {
            retorno = Integer.valueOf(inString().trim()).intValue();
            finished = true;
         } catch(NumberFormatException e) { 
            System.out.println("Invalid input. Not an integer");
         }
      }
      return retorno;
   }

   public boolean inBoolean() {
      boolean finished = false;
      boolean retorno = false;
      while(!finished){
         //inputFlush();
         //printPrompt(prompt);
         try {
            int tmp = Integer.valueOf(inString().trim()).intValue();
            if (tmp == 1){
               retorno = true;
            } else if (tmp == 0) {
               retorno = false;
            } else { 
               NumberFormatException nfe = new NumberFormatException();
               throw nfe;
            }
            finished = true;
         } catch(NumberFormatException e) { 
            System.out.println("Invalid input. Not a boolean");
         }
      }
      return retorno;
   } 

}


Topic ClasseEntradaFinal . { View | Diffs | r1.1 | More }
Revision -
Revision r1.1 - 07 Jul 2005 - 22:53 - AndreGermanoRegert
Copyright © 1999-2003 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding XP? Send feedback.