4
I have a problem with this exercise here:
Write a class that validates data (Validacao
), with a method to validate a given name (ehNomeValido(nome)
). The method must return true
pass the following rules:
If the parameter is not null.
If the parameter is not a
String
emptyIf the parameter has two particles (two words separated by a space)
The problem is that the program only returns me the false
in the case of the name I put as parameter the program should return true
. Where am I wrong? I’ve 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"));
}
}
Please make an intuitive title for the question, write help please is totally redundant, everyone who are asking on the site are already looking for help, so it’s obvious, write a useful title setting the problem helps to increase people’s interest.
– Guilherme Nascimento
@Gandalf, the code should also cover names with more than 2 words?
– Dherik
Did any of the answers solve your question? Do you think you can accept one of them? Check out the [tour] how to do this, if you haven’t already. You would help the community by identifying what was the best solution for you. You can accept only one of them. But you can vote on any question or answer you find useful on the entire site.
– Maniero