比较字符串,数组形式
从命令行传入一个包含十个字符的字符串,把该字符串与程序中给定的字符串"bacdbcabca"依次比较,统计两个串中对应字符相等的数目。然后输出命令行输入的字符串,并把两个串中对应字符不相等的字符替换为'@'后生成的新串输出,最后输出两个串中相等字符的数目package ch3;
import java.util.Scanner;
public class compare {
String a[] = new String[10];
public static void main(String[] args) {
int t = 0;
String[] b = new String[]{"bacdbcabca"};
for (String n : b)
System.out.print(n + " ");
System.out.println();
Scanner stdin = new Scanner(System.in);
String a[] = new String[10];
for (int i = 0; i < 10; i++) {
a[i] = stdin.next();
if (!(a[i].equals(b[i]))) {
t++;
a[i] = "@";
}
}
System.out.println(t);
for (String n : a)
System.out.print(n);
}
}
运行不起来,求找错