+ 1
I can't print my array with int a = arr.length
If I put a number instead "a" my sister.out.println(arr[a]); It works perfectly but if I use arr[a] it send a wrong 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(); int a = 0 ; int x = arr.length; while (a <= x){ System.out.println(arr[a]); a++; } } }
4 Answers
+ 2
Do you have a question? I don't see a question or problem here.
+ 2
Yes, Ipang is right.
You probably want < instead of <=.
while (a < x){
System.out.println(arr[a]);
a++;
}
+ 1
Sorry, the title is I can't instead I can
+ 1
Your while loop should run while <a> less than <x>, not while <a> less than or equal to <x>.
while( a < x )