Jump to content

Recommended Posts

Posted

Boas,

estou a fazer um programa e não estou a fazer como fazer o seguinte,

por exemplo escrevo: BGT123 ou 123ABC se a primeira e a segunda letra é uma letra do abc e não um numero.

String abc = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
String c;

podia fazer c.charAt(0)==abc.charAt(0....25) mas assim nunca mais sai de aqui!

já tentei com for mas não estou a conseguir,

Obrigado!

...º(>_<)º...

Posted (edited)

Podes comparar com a classe character.

Character.isLetter(c.chartAt(posicao));

ou

Character.isDigit(c.chartAt(posicao));

(Não pus em code porque está a dar erro)

Edited by NunoDinis

Estranha forma de vida que tem a capacidade de transformar comandos em mensagens de erro.

ndsotware.org

Posted

Podes comparar com a classe character.

Character.isLetter(c.chartAt(posicao));

ou

Character.isDigit(c.chartAt(posicao));

(Não pus em code porque está a dar erro)

Também não consigo com o character.

...

...º(>_<)º...

Posted (edited)

e que tal apresentares o código que tens ?

 Scanner teclado = new Scanner(System.in);

 Scanner teclado = new Scanner(System.in);
       String matricula;

       //NN-NN-LL, NN-LL-NN, LL-NN-NN (L)-Letra [A,Z] (N) - Numero [0,9]
       System.out.println("Introduza uma matricula");
       System.out.println("Formato→ NN-LL-NN  onde (N→Numeros [0,9] e (L→Letras [A,Z])");
       matricula = teclado.next();


       if( Character.isDigit(matricula.charAt(3)) 
        || Character.isDigit(matricula.charAt(4)) )
               {
               System.out.println("NAo tem letras");  

       }
}

já da +/- agora falta fazer para o formato NN-LL-NN

Edited by Tim§id€

...º(>_<)º...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.