Tuesday 13 June 2017

How to reverse string in java

Program:

package JavaCoders;

import java.util.Scanner;
public class rev_string
{
public static void main(String[] args)
{
String str1="";
String str2="";
System.out.println("Enter the string to be reversed:\n");
Scanner scn=new Scanner(System.in);
str1=scn.next();
for(int i=str1.length()-1;i>=0;i--)
{
str2=str2+str1.charAt(i);
}
System.out.println("Reversed String is: "+str2);
}
}

OUTPUT:

How-to-reverse-string-in-java

You can also go to link that ellaborate it more:

1 comment:

  1. Well explained string operation .
    there are good String program collection visit Top String program

    ReplyDelete

Oracle / PLSQL: FOR LOOP

set serveroutput on; declare a1 varchar2(100); begin select count(*) into a1 from employees; for i in 1..a1 loop dbms_output.put_line...