求一个完整的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);
}
}
2019-07-27
参见科技与人文网(网页链接),里数渗面有Java相拿陆关问题以及解决方案并且附有完整代码消毕顷,你想要什么代码就有什么代码。
给悔游你孝漏个入门的!
public
class
Hello{
public
static
void
main(String[]
args){
System.out.println("碧慎销Hello
World!");
}
}