0

When I put the code to invoke reverse string between Invoke array and power functions the eclipse scape all the steps of reverse string invoke why? I need to make invoke string reverse between these array and power of number

// 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);
}

}

  • Please [edit] your question to properly format your code. – maloomeister Jun 11 '21 at 07:29
  • Yes, the problem solved Thanks @maloomeister , but is that a problem with java or eclipse? – Mohamed Elkady Jun 11 '21 at 07:50
  • 1
    It is neither a problem with eclipse nor java. This is not a bug, but the normal behavior of the `Scanner`, when using the `nextLine()` in combination with other `nextX()` methods. Read the linked post and the answers for a detailed explanation. – maloomeister Jun 11 '21 at 07:53

0 Answers0