answersLogoWhite

0


Best Answer

package sara78;

import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStreamReader;

import java.util.Scanner;

import java.lang.IndexOutOfBoundsException;

public class node extends RuntimeException{

private static String string;

/**

* @param args

*/

public static void main(String[] args) {

// TODO Auto-generated method stub

InputStreamReader input = new InputStreamReader(System.in);

BufferedReader reader = new BufferedReader(input);

try {

string = reader.readLine();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

char[] c=string.toCharArray();

int k=c.length;

for(int i=0;i<=k;i++)

{

System.out.println(""+c[i]);

}

for(int i=k;i<=k;--i)

{

System.out.println(""+c[i]);

}

}

}

As well, you could do it with a different approach, same idea:

import java.util.*;

public class Example

{

public static void main(String[] args)

{

Scanner in = new Scanner(System.in);

System.out.println("Please enter a String to reverse:");

String toReverse = in.next();

String Reversed = "";

for (int i = toReverse.length()-1; i>=0; i--)

{

Reversed = Reversed + toReverse.charAt(i);

}

System.out.println(Reversed);

}

}

User Avatar

Wiki User

12y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

13y ago

public class ReverseStringTest {

public static void main(String[] args) {

String str = "What's going on?";

System.out.println(ReverseString.reverseIt(str));

}

}

class ReverseString {

public static String reverseIt(String source) {

int i, len = source.length();

StringBuffer dest = new StringBuffer(len);

for (i = (len - 1); i >= 0; i--)

dest.append(source.charAt(i));

return dest.toString();

}

}

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

import java.util.*;

public class Example

{

public static void main(String[] args)

{

Scanner in = new Scanner(System.in);

System.out.println("Please enter a string to reverse:");

String input = in.next();

String reversed = "";

for (int i = 0; i<input.length(); i++)

{

reversed = input.charAt(i) + reversed;

}

System.out.println("The reversed string is: " + reversed);

}

}

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

int[] iArrNumbers = new int[5];

for(int iLoop = 0; iLoop < 5; iLoop++)

iArrNumbers[iLoop] = (iLoop + 4) * (((iLoop + 1) * (iLoop + 1) * 4) + 4); // increasing but not adjacent


// So now the array is: 32, 100, 240, 476, 832


// Reverse in a simple (although perhaps not the most efficient manner)
List lstNumbers = Arrays.asList(iArrNumbers);

Collections.reverse(lstNumbers);


for(int iLoop = 0, iLength = lstNumbers.size(); iLoop < iLength; iLoop++)

iArrNumbers[iLoop] = lstNumbers.get(iLoop);


// iArrNumbers is now: 832, 476, 240, 100, 32 (my math beside the point)

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

public static final String reverseString(final String str) {

return new StringBuilder(str).reverse().toString();

}

This answer is:
User Avatar

User Avatar

Wiki User

10y ago

Collections.reverse(list);

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Program to reverse a string in java?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is the use of Reverse String in C program?

The use of the reverse string in C program is used to reverse the letters in the string. An example would be reverse me would be reversed to em esrever.


String reverse program with single string and without using library functions in java?

You can create a separate string initially empty. Then using a loop, start at the end of the string and add it to the end of the other string. At the end of the loop, the other string would contain the reverse.


How does the string trim work in Java?

The string trim works in Java by trimming white space from the beginning and end of a string. It cleans up the string and makes makes it neater for the users of the program.


Write a program in java to display a string message using Servlets?

i dont no string for servlate


How do you program a reverse auto loan calculator in JAVA?

In order to program a reverse auto loan calculator in JAVA, you are going to need a lot of experience with JAVA. There are online tutorials that can help you set up with fundamentals of JAVA so that you will be able to create almost any basic program you want.


Write a program to implement the various operations on string such as length of string concatenation reverse of a string copy of a string to another in VB?

what is string


Write a java program to count the space from the given line?

.... String line = "This is example program with spaces"; String[] tokens = line.split(" "); System.out.println(tokens.length-1); .......


Java program to convert lowercase to uppercase?

You can use the toUpperCase() method on a String to convert any String to all uppercase.


What is string buffer in java?

StringBuffer is java class available in java.lang package which provides mutable String object where String is immutable class. The methods of this class like reverse(), append(),insert() gives facility to insert data of the same object.


Write the program in Linux to find the reverse of any string?

i am sam


Write a java program to pass a string have a good day from command line?

public class HaveAGoodDay { public static void main(String[] args) { for (final String arg : args){ System.out.print(arg +" "); } } } compile and run the program: java HaveAGoodDay have a good day. output: have a good day.


How to write a program in python to print the reverse of a number?

In python, type the following into a document. NOTE: Sentences following a # symbol are comments, and are not necessary for the program to run. #!/usr/bin/python #This program takes a input from a user and reverses it. number = input("Type a number: ") #This takes input from a user. a = len(number) #This finds the length of the number reverse = "" #This sets the variable reverse to an empty string. for i in number: a = a-1 #The places in a string start from 0. The last value will be the length minus 1.reverse = reverse + number[a] #Makes the number's last digit the new string's first. print("The reverse of", number, "is", reverse + ".") #prints the resulting string. This program will take any sequence of characters and reverse them. The final value is a string, but if an integer is needed, one needs only to add the line reverse = int(reverse) above the print statement. However, this will stop the program from being able to reverse strings, as it is not possible to convert a string to an integer if it is not a number.