微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

运行我的代码调用函数时出错

如何解决运行我的代码调用函数时出错

当我在 Invoke array 和 power 函数之间放置代码调用反向字符串时,eclipse scape 反向字符串调用的所有步骤为什么?我需要在这些数组和数字的幂之间反转调用字符串

// function to take base and exponent and return the power
public static long power(int base,int exponent){
    long powResult = 1;
    for (int i = 0; i < exponent; i++) {
        powResult = powResult * base;
    }
    return powResult;
}
// function to take string and return the reverse
public static String reverse(String s) {
    String result = "";
    for (int i = s.length()-1; i >=0; i--) {
        result += s.charat(i);
    }
    return result;
}
// function to reverse Array and return the new Array reversed
public static int[] arrReverse(int[] a) {
    int [] result = new int[a.length];
    int j = 0;
    for (int i = a.length-1; i>=0; i--) {
        result[j] = a[i];
        j++;
    }
    return result;
} 
public static void main(String[] args) {
    Scanner input = new Scanner(system.in);
    // take an integer array from user
    System.out.println("Enter your Array length : ");
    int len = input.nextInt();
    int [] arr = new int[len];
    System.out.println("Enter your numbers : ");
    for (int i = 0; i < len; i++) {
        arr [i] = input.nextInt();
    }
    // invoke Array reverse function
    int [] torev = arrReverse(arr);
    for (int i = 0; i < torev.length; i++) {
        System.out.println(torev[i]);
    }
    // the a problem here running the eclipse scape this step
    **// invoke string reverse function
    System.out.println("Enter your string : ");
    String myString = input.nextLine();
    String Apply = reverse(myString);
    System.out.println("Your reverse string is : " + Apply);**
    // invoke power function
    // (x)10 + (x)7 + (2x)5 + (10x)3
    System.out.println("Enter your x number: ");
    int x = input.nextInt();
    long v1 = power(x,10);
    long result = v1;
    System.out.println("your input : "+ x);
    System.out.print("your result : "+ result);
}

}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。