I am doing a project for school right now, a mini text editor. One of the basic functions is letting the user insert text, obviously. The point if for us to control input, use loops, stings and arrays.
do{
System.out.println("Insira o seu texto (duplo ENTER volta ao Menu):");
linhas [nLinhas] = input.nextLine();
}
while (!Arrays.asList(linhas).contains(""));
I'm asking the user to enter text, and when they do a double ENTER, they'll be back to the Menu. However, this isn't happening... I've added the cointains from a search I did online, but I can't use it, otherwise I'm going to be penalized...
I have to do this with a do-while, so how do I set up the while? I have tried this using a split, since the objective is to make the text input stop whenever a line with "" (nothing) is inserted, but it didn't work...
Any help would be awesome!
UPDATE:
switch (escolhaMenu){
case 'i':
case 'I':
System.out.println("\nEscolheu a opção: \"Inserir linhas no fim (termine com uma linha vazia)\"\n");
do{
System.out.println("Insira o seu texto (duplo ENTER volta ao Menu):");
linhas [nLinhas] = input.nextLine();
}
while (!Arrays.asList(linhas).contains(""));
break;
Rewrite as question did change...
If you read into array... how large is it? Do you need second condition to not run over the array length?
Some comments in your code:
Wouldn't it be
?
As in, you want to check that the Array doesn't contain an empty string?
Also, I see your note about not being able to use "contains" . . . Try this:
I don't understand why you are putting the line into an array and then checking the entire array for "". You should probably just be checking for what is in line you just read. Why would it matter what came before?