问题描述
我正在为学校做一个项目,一个迷你文本编辑器。其中一个基本功能是让用户插入文本。关键是我们要控制输入,使用循环,蜇和数组。
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...
任何帮助都会很棒!
更新:
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;
推荐答案
不会是
while (!Arrays.asList(linhas).contains(""));
?
如你所愿检查数组是否包含空字符串?
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:
boolean done = false;
do {
do stuff
String input = input.nextLine();
if (input.equals("") {
done = true;
}
} while (!done) ;
这篇关于识别字符串数组中的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!