Thursday, February 18, 2016

How to show a mirror to a Sting ( in java)



//In this program we will read a user input String through Scanner and reverse it.



import java.util.Scanner;
public class StringReversal {
public static void main(String[]args){
Scanner input = new Scanner(System.in);
print("Enter a string : ");
    String s = input.nextLine();
    String reverse ="";
for(int j = s.length()-1;j>=0;j--){
reverse +=""+s.charAt(j);
}
System.out.printf("Reversed string :%s",reverse);
}
private static void print(String msg){
System.out.printf("%s",msg);
}

}


Output: 

Enter a string : University
Reversed string :ytisrevinU

No comments: