软件测试——代码覆盖率
第一题:
import java.util.Scanner;
public class A {
public static void main (String[] args){
A a = new A(); a.View();
}
public void findWord(String str){
String[] arrayWord =str.split(" ");
for(int i=arrayWord.length-1;i>=0;i--){
System.out.print(arrayWord[i]+" ");
}
} public void View(){
Scanner input =new Scanner(System.in);
System.out.println("please input:");
String str=input.nextLine();
A a = new A();
a.findWord(str);
}
}
第二题:
import java.util.Scanner;
public class CE { public static void main (String[] args){
CE a = new CE(); a.View();
} public void View(){
Scanner input =new Scanner(System.in);
System.out.println("请输入字符串:");
String str=input.nextLine();
CE a = new CE(); a.findWord(str);
} public void findWord(String str){
String[] arrayWord =str.split(" ");
CE a = new CE(); a.frequency(arrayWord);
} public void frequency(String[] arrayWord){
String[] word = new String[arrayWord.length];
int time[]=new int[arrayWord.length];
boolean t = true;
for(int i=0;i<arrayWord.length;i++){
for(int j=0;j<arrayWord.length;j++){
if(arrayWord[i].equals(word[j])){
System.out.println("单词重复");
t=false; } }
if(t==true){
word[i]=arrayWord[i];
time[i]=1;
for(int j=i+1;j<arrayWord.length;j++){
if(arrayWord[i].equals(arrayWord[j])){
time[i]++; }
}
}
}
for(int i = 0;i<arrayWord.length;i++){
if(word[i]!=null){
System.out.println("单词:"+word[i]+"出现了"+time[i]+"次。"); } } } }