所以这里是Pschemo我的整个代码,非常感谢,没有问题没有错误,一切都很好。但是,当我第一次输入数组的所有元素并输入stop时,只需要一件事,我在编写System.out.println()时会移动一行,然后我必须再次按Enter键,然后它显示了我设计的Thank You消息和Output的其余部分。为什么会这样?
任何线索?
import java.util.ArrayList;
import java.util.Scanner;
import java.util.concurrent.TimeUnit;
class End_Start_Vowels
{
public static void main() throws InterruptedException
{
String fs="yes";
while(fs.equalsIgnoreCase("yes"))
{
Scanner in=new Scanner(System.in);
ArrayList <String> a= new ArrayList<String>();
String b; int c=0;
char d;
int total=0;
int v=0;
int o=0;
int w=0;
int e=0;
int l=0;
System.out.println("start tping below, type stop or end to stop.");
do
{
b=in.nextLine();
a.add(b);
c++;
}
while(!b.equalsIgnoreCase("stop")&&!b.equalsIgnoreCase("end"));
if(c<2)
a.clear();
int z=a.size();
if(c>=2)
a.remove(z-1);
System.out.println();
if(c<2)
System.out.println("No word are typed. Please type continue to restart it");
String s1=in.nextLine();
if(c<2)
{ if(s1.equalsIgnoreCase("continue")){
System.out.println("start tping below, type stop or end to stop.");
do
{
b=in.nextLine();
a.add(b);
c++;
}
while(!b.equalsIgnoreCase("stop")&&!b.equalsIgnoreCase("end"));
if(c<2)
a.clear();
z=a.size();
if(c>=2)
a.remove(z-1);
System.out.println();
for(int j=0;j<a.size();j++)
{
String s=a.get(j);
for(int i=0;i<s.length();i++)
{
d=s.charAt(i);
if(d=='a'||d=='A')
{v++; total++;}
if(d=='E'||d=='e')
{ o++; total++;}
if(d=='i'||d=='I')
{w++; total++;}
if(d=='O'||d=='o')
{ e++; total++;}
if(d=='u'||d=='U')
{ l++; total++;}
}
}
if(c>=2)
{
System.out.println("Thanks for using!");
TimeUnit.SECONDS.sleep(1);
System.out.println("Showing you the frequencies of each vowels.");
TimeUnit.SECONDS.sleep(1);
System.out.println();
System.out.println("Frequency of vowel a is ="+v);
System.out.println("Frequency of vowel e is ="+o);
System.out.println("Frequency of vowel i is ="+w);
System.out.println("Frequency of vowel o is ="+e);
System.out.println("Frequency of vowel u is ="+l);
System.out.println();
System.out.println("Total number of vowels present is ="+total);
}
}
}
else
{
for(int j=0;j<a.size();j++)
{
String s=a.get(j);
for(int i=0;i<s.length();i++)
{
d=s.charAt(i);
if(d=='a'||d=='A')
{v++; total++;}
if(d=='E'||d=='e')
{ o++; total++;}
if(d=='i'||d=='I')
{w++; total++;}
if(d=='O'||d=='o')
{ e++; total++;}
if(d=='u'||d=='U')
{ l++; total++;}
}
}
if(c>=2)
{
System.out.println("Thanks for using!");
TimeUnit.SECONDS.sleep(1);
System.out.println("Showing you the frequencies of each vowels.");
TimeUnit.SECONDS.sleep(1);
System.out.println();
System.out.println("Frequency of vowel a is ="+v);
System.out.println("Frequency of vowel e is ="+o);
System.out.println("Frequency of vowel i is ="+w);
System.out.println("Frequency of vowel o is ="+e);
System.out.println("Frequency of vowel u is ="+l);
System.out.println();
System.out.println("Total number of vowels present is ="+total);
}
}
System.out.println();
TimeUnit.SECONDS.sleep(1);
System.out.println("Do you want to use it again, type yes to continue.");
fs=in.nextLine();
System.out.println();
}
}
}