0
Why won't this work?
Code: import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String text = scanner.nextLine(); char[] arr = text.toCharArray(); //your code goes here int arrayLength; arrayLength = arr.length(); String result; for (int arrLength = arrayLength - 1; arrLength >= 0; arrLength--) { char transResult = arr[arrLength]; result += transResult; } System.out.println(result); } } Error Message: /usercode/Program.java:12: error: cannot find symbol arrayLength = arr.length(); ^ symbol: method length() location: variable arr of type char[] 1 error
2 Antworten
+ 1
And you need to initialize String result.
String result = "";
Btw: you don't need an extra variable for arr.length, you can just use arr.length directly.
for(int arrLength = arr.length - 1; arr.length >= 0; arrLength--){
}
0
length is a property, so it would be arr.length instead of arr.length().