解决方案 »

  1.   

    你不用编辑器?for(int i=0;i<a.length;i++){//用来检测输入的字符是否是数组B中定义的字符范围
    for(int j=0;j<b.length;j++){
    if(str.charAt(i)==b[j]){
    c[i]=b[j];
    };
    };
    };这么多分号
      

  2.   

    仔细想想你的各charAt的索引有没有问题
    像if(str.length()>10)不符合条件的话直接return就行了,打印一句话有什么用。而且再输入完之后就应该判断
      

  3.   

    你的程序改了下,试试吧
    import java.util.*;public class xuexi {
    public static void main(String[] args) { try {
    Scanner sc = new Scanner(System.in);
    String str = sc.nextLine();// 用来输入字符串

    // 用来检测字符串的长度
    if (str.length() > 16 || str.length() < 2) {
    System.out.println("您的输入超出预定范围!");
    return;
    }
    char[] a = new char[str.length()];// 用来接收输入的字符串
    for (int k = 0; k < str.length(); k++) {
    a[k] = str.charAt(k);// 将输入的字符串,一个字符一个字符的赋值给数组A
    } char[] b = { 'a', 'b', 'c', 'd', 'e', 'f' };// 用来比较输入的字符范围
    char[] c = new char[16];// 用来接收测试过的字符串 for (int i = 0; i < a.length; i++) {// 用来检测输入的字符是否是数组B中定义的字符范围
    for (int j = 0; j < b.length; j++) {
    if (str.charAt(i) == b[j]) {
    c[i] = b[j];
    }
    ;
    }
    ;
    }
    StringBuilder asb = new StringBuilder();
    StringBuilder csb = new StringBuilder();
    asb.append(a);
    csb.append(c);
    System.out.println("asb.toString():"+asb.toString().trim());
    System.out.println("csb.toString():"+csb.toString().trim());

    if (csb.toString().trim().equals(asb.toString().trim())) {// 用来检测最后的输出结果
    System.out.print(c);
    } else {
    System.out.print("您的输入不合理!");
    } } catch (Exception e) {
    e.printStackTrace();
    System.out.println("程序出错!");
    } }
    }
      

  4.   


    你那a长度是10 ,c长度16, 完了还没用数组的比较去比,肯定是一串的不合理了
    System.outprint("您的输入不合理!");//这个应该编译不过,改成System.out.print("您的输入不合理!");
    直接在你那上面改改import java.util.*;public class xuexi{
    public static void main(String[] args){try{
    Scanner sc = new Scanner(System.in);
    String str = sc.nextLine();//用来输入字符串
    char[] a = new char[10];//用来接收输入的字符串
    for(int k=0;k<a.length;k++){
    a[k]=str.charAt(k);//将输入的字符串,一个字符一个字符的赋值给数组A
    }char[] b = {'a','b','c','d','e','f'};//用来比较输入的字符范围
    char[] c = new char[10];//用来接收测试过的字符串for(int i=0;i<a.length;i++){//用来检测输入的字符是否是数组B中定义的字符范围
    for(int j=0;j<b.length;j++){
    if(str.charAt(i)==b[j]){
    c[i]=b[j];
    }
    }
    }if(Arrays.equals(a,c)){//用来检测最后的输出结果
     System.out.print(c);
     System.out.println("成功!");
    }
    else{
    for(int i=0;i<a.length;i++){
    System.out.print(c[i]);
    }
    //System.out.println(str);
    for(int i=0;i<a.length;i++){
    System.out.print(a[i]);
    } System.out.println("您的输入不合理!");
    }if(str.length()>10){ System.out.println("您的输入超出预定范围!"); }
                    //用来检测字符串的长度}catch(Exception e){ 
                   System.out.println("程序出错!"); 
            }
    }
    }
      

  5.   

    而且你用charAt的话, 你得输入相应长度,像你这样要10个字符输入5个肯定出错
    charAt
    public char charAt(int index)返回指定索引处的 char 值。索引范围为从 0 到 length() - 1。序列的第一个 char 值位于索引 0 处,第二个位于索引 1 处,依此类推,这类似于数组索引。 
    如果索引指定的 char 值是代理项,则返回代理项值。 
    指定者:
    接口 CharSequence 中的 charAt
    参数:
    index - char 值的索引。 
    返回:
    此字符串指定索引处的 char 值。第一个 char 值位于索引 0 处。 
    抛出: 
    IndexOutOfBoundsException - 如果 index 参数为负或小于此字符串的长度。
      

  6.   

    把楼主的代码稍微改了下,可以看看,我试了几个,可以package src.com.neusoft;import java.util.Scanner;public class test { /**
     * @param args
     */
    public static void main(String[] args) {
    // TODO Auto-generated method stub try{
    Scanner sc = new Scanner(System.in);
    String str = sc.nextLine();//用来输入字符串
    int length = str.length();
    if(length > 10){
     System.out.println("您的输入超出预定范围!");
     return;
    }else {
    char[] a = new char[length];//用来接收输入的字符串
    for(int k=0;k<a.length;k++){
    a[k]=str.charAt(k);//将输入的字符串,一个字符一个字符的赋值给数组A
    }
    char[] b = {'a','b','c','d','e','f'};//用来比较输入的字符范围
    //char[] c = new char[length];//用来接收测试过的字符串
    StringBuffer c = new StringBuffer();

    for(int i=0;i<a.length;i++){//用来检测输入的字符是否是数组B中定义的字符范围
    for(int j=0;j<b.length;j++){
    if(str.charAt(i)==b[j]){
    //c[i]=b[j];
    c.append(b[j]);
    continue;//结束本次循环
    }
    }
    }
    //if(c.equals(a)){//用来检测最后的输出结果
    if (c.toString().equals(str)) {
    System.out.print(c);
    }else{
    System.out.print("您的输入不合理!");
    }
    }
    }catch(Exception e){ 
    System.out.println("程序出错!"); 
    }
    }}
      

  7.   

    还有你那个char[] a = new char[length];//用来接收输入的字符串
    for(int k=0;k<a.length;k++){
    a[k]=str.charAt(k);//将输入的字符串,一个字符一个字符的赋值给数组A
    }一点用都没有呀!!