Olá pessoal,
preciso fazer uma função que retorne verdadeiro ou falso se o valor parametrizado nela(do tipo String) está no intervalo de A a Z;
Outra função para retornar verdadeiro ou falso se o valor parametrizado está no intervalo de 0 a 9 e ainda aceite os caracteres ( - ou .). Não aceite letras.
Outra função para retornar verdadeiro ou falso se o valor parametrizado é numerico e positivo.
Alguém pode me ajudar?
:arrow: :arrow: :arrow: :arrow: :arrow: :arrow: :arrow: :arrow:Abraços
Mantu
Dezembro 10, 2006, 1:50pm
#2
[code]
/**
@author Mantu;
*/
package br.com.mantu.help.guj.NandaComp;
public class StringVerifier {
public static boolean haveOnlyUpperCaseLetters(String text) {
return text.matches("[A-Z]+");
}
public static boolean isNumber(String text) {
return text.matches("[-+]?\d+\.\d+");
}
public static boolean isPositiveNumber(String text) {
return text.matches("\d+\.\d+");
}
}
class TestStringVerifier{
public static void main(String[] args) {
String
aText = “Some text…”,
aOnlyUpperCaseLettersText = “STREIGHTFORWARDNESS”,
aMessedNumberText = “77+893-34.349.3349-394.3.”,
aNumberText = “-3748.6875”,
aPositiveNumber = “33262.33”
;
verify(aText);
System.out.println();
verify(aOnlyUpperCaseLettersText);
System.out.println();
verify(aMessedNumberText);
System.out.println();
verify(aNumberText);
System.out.println();
verify(aPositiveNumber);
}
private static void verify(String text) {
System.out.println("StringVerifier.haveOnlyUpperCaseLetters(\"" + text + "\"): " + StringVerifier.haveOnlyUpperCaseLetters(text));
System.out.println("StringVerifier.isNumber(\"" + text + "\"): " + StringVerifier.isNumber(text));
System.out.println("StringVerifier.isPositiveNumber(\"" + text + "\"): " + StringVerifier.isPositiveNumber(text));
}
}[/code]