求Java语言编写的可测试的程序源代码
跪求一个关于Java语言编写的程序源代码,要求:50行以上,有输入,有输出,最好有输入的边界范围限制的,可供测试的。程序结果有错误也没关系,可供测试就行。急需!谢谢!能补...
跪求一个关于Java语言编写的程序源代码,要求:50行以上,有输入,有输出,最好有输入的边界范围限制的,可供测试的。程序结果有错误也没关系,可供测试就行。急需!谢谢!
能补充一下注解和程序介绍吗?!谢谢 展开
能补充一下注解和程序介绍吗?!谢谢 展开
1个回答
展开全部
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class DoChar {
private BufferedReader buf;
public void getWord() {
buf = new BufferedReader(new InputStreamReader(System.in));
try {
int a=0;
int b=0;
int c=0;
int d=0;
int e=0;
String str = buf.readLine();
char[] word = str.toCharArray();
for(int i=0;i<word.length;i++){
if(word[i]=='a'){
a++;
}
if(word[i]=='b'){
b++;
}
if(word[i]=='c'){
c++;
}
if(word[i]=='d'){
d++;
}
if(word[i]=='e'){
e++;
}
}
System.out.println("a is "+a);
System.out.println("b is "+b);
System.out.println("c is "+c);
System.out.println("d is "+d);
System.out.println("e is "+e);
String[] strs = str.split(" ");
for(int i=0;i<strs.length;i++){
System.out.println(strs[i].length());
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void main(String[] args) {
DoChar demo = new DoChar();
demo.getWord();
}
}
import java.io.IOException;
import java.io.InputStreamReader;
public class DoChar {
private BufferedReader buf;
public void getWord() {
buf = new BufferedReader(new InputStreamReader(System.in));
try {
int a=0;
int b=0;
int c=0;
int d=0;
int e=0;
String str = buf.readLine();
char[] word = str.toCharArray();
for(int i=0;i<word.length;i++){
if(word[i]=='a'){
a++;
}
if(word[i]=='b'){
b++;
}
if(word[i]=='c'){
c++;
}
if(word[i]=='d'){
d++;
}
if(word[i]=='e'){
e++;
}
}
System.out.println("a is "+a);
System.out.println("b is "+b);
System.out.println("c is "+c);
System.out.println("d is "+d);
System.out.println("e is "+e);
String[] strs = str.split(" ");
for(int i=0;i<strs.length;i++){
System.out.println(strs[i].length());
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void main(String[] args) {
DoChar demo = new DoChar();
demo.getWord();
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询