Question 48 : Write a program inn Java to reverse a String taken as input in Java.
Sample input : JAVA
Sample output : AVAJ
Java Program :
class string_rev
{
static void reverse(String s)
{
String rev="";
int i;
for(i=s.length()-1;i>=0;i--)
rev=rev+s.charAt(i);
System.out.print("String input : "+s);
System.out.print("\n\nReversed string : "+rev);
}
}
Sample input : JAVA
Sample output : AVAJ
Java Program :
class string_rev
{
static void reverse(String s)
{
String rev="";
int i;
for(i=s.length()-1;i>=0;i--)
rev=rev+s.charAt(i);
System.out.print("String input : "+s);
System.out.print("\n\nReversed string : "+rev);
}
}
Say original s=hi my name
ReplyDeleteAnd the output that we want=name my hi
What to do in this
case
What should I type in the parameters?
ReplyDelete