I am trying to reverse array String from the user and I had one problem how can I out put the elements without new array. I don't know what should I write to output the content. However, I tried most of the examples*(a[i], a[i+1]) and if run it I got null.
here is my code:
import java.util.Scanner;
public class ReverseArray {
public static void main(String[] args) {
int i=0;
String temp =null;
String o=null;
int pos =0;
String a [];
Scanner kb = new Scanner (System.in);
System.out.print("Enter a sentence: ");
o = kb.nextLine();
a = new String [o.length()];
for( i =0; i< (o.length()/2)-1; i++){
temp = a[i];
a[i] = a[o.length()-(i+1)];
a[o.length()-(i+1)] = temp;
}
}