求一个完整的java程序
降低下要求,能把双写字母改成单写,设置输入Y或y进入下一个循环,输入n结束程序 做出来就OK 展开
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
public class TestString {
public static void main(String[] args) throws IOException {
boolean flag = false;
do {
System.out.println();
System.out.println("Do you want to continue?(Y/N)");
Scanner scan = new Scanner(System.in);
String banlance = scan.next();
if (banlance.equals("Y")) {
flag = true;
} else if(banlance.equals("N")) {
System.out.println("End!");
break;
} else {
System.out.println("Error Input!");
}
System.out.print("Please input the String: ");
BufferedReader br = new BufferedReader(new InputStreamReader(
System.in));
String str = br.readLine();
StringBuffer strBuffer = new StringBuffer(str);
for(int i=0; i<strBuffer.length(); i++) {//将元音字母先删掉
char c = strBuffer.charAt(i);
if ((c == 'a') || (c == 'e') || (c == 'i') || (c == 'o') || (c == 'u')) {
strBuffer = strBuffer.deleteCharAt(i);
--i;
}
}
for(int i=0,j=i+1; j<strBuffer.length(); i++,j++) {//处理重复辅音字母
char c1 = strBuffer.charAt(i), c2 = strBuffer.charAt(j);
if(c1 == c2) {
strBuffer = strBuffer.deleteCharAt(i);
--i;
--j;
}
}
System.out.println(strBuffer);
} while (flag = true);
}
}
测试与结果:
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
public class StringTest {
public static void main(String[] args) throws IOException {
String str="";
do {
System.out.println("Please enter :");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
str=br.readLine();
if ("Y".equals(str)||"y".equals(str)) {
continue;
}else if ("N".equals(str)||"n".equals(str)) {
return;
}
char[]chars=str.toCharArray();
ArrayList list=new ArrayList();
for (int i = 0; i < chars.length-1; i++) {
if (chars[i]==chars[i+1]) {
i++;
}
list.add(chars[i]);
System.out.print(chars[i]);
}
System.out.println(chars[chars.length-1]);
} while (true);
}
}
给你个入门的!
public
class
Hello{
public
static
void
main(String[]
args){
System.out.println("Hello
World!");
}
}