I have a problem with this exercise here:
Write a class that does data validation ( Validacao
), with a method to validate a proper name ( ehNomeValido(nome)
). The method should return true
if it passes the following rules:
-
If the parameter is not null.
-
If the parameter is not an empty%%
-
If the parameter has two particles (two words separated by a space)
The problem is that the program only returns me String
and in the case of the name that I put as a parameter the program should return false
. Where am I going wrong? I have already rewritten the code several times in other ways and nothing.
public class NOVOTESTE2{
public static boolean validacao(String nome){
if((nome != null) && (nome.isEmpty() == false) && (nome.indexOf(" ") == 1)){
return true;
}else{
return false;
}
}
public static void main(String[] args){
System.out.println(validacao("Rodrigo Moreira"));
}
}