REVERSE GIVEN STRING OR A NUMBER
JAVA CODE :)
import java.util.Scanner;
public class Reverse
{
public static void main(String[] args)
{
int n,rem,revnum=0;
Scanner sc=new Scanner(System.in);
System.out.print("Enter a String:");
String str=sc.nextLine();
String s="";
for(int j=0;j<str.length();j++)
{
s=str.charAt(j)+s;
}
System.out.print("Reversed String:"+s);
System.out.print("\nEnter a number:");
n=sc.nextInt();
sc.close();
while(n>0)
{
rem=n%10;
revnum=revnum*10+rem;
n=n/10;
}
System.out.print("Reversed number:"+revnum);
}
}
0 Comments