Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String input = scanner.nextLine(),
- reverseString = "";
- for (int i = input.length() - 1; i >= 0; i--){
- reverseString += input.charAt(i);
- }
- System.out.println(reverseString);
- }
- }
- Solution with methods:
- import java.util.Scanner;
- import java.io.*;
- class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String reverseString = new StringBuilder(scanner.nextLine()).reverse().toString();
- System.out.println(reverseString);
- }
- }
- OR:
- import java.util.Scanner;
- import java.io.*;
- class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- System.out.println(new StringBuilder(scanner.nextLine()).reverse().toString());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement