Advertisement
Guest User

Untitled

a guest
Oct 1st, 2014
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.82 KB | None | 0 0
  1. //Task 10. Написать метод, принимающий в качестве параметра строку. Возвращающий перевернутую строку.
  2.  
  3. package tasks;
  4. import java.util.Scanner;
  5. public class Task10 {
  6.     public static void main(String[] args) {
  7.         Scanner scan = new Scanner(System.in);
  8.         String line = scan.nextLine();
  9.         printLine(line);
  10.         flip(line);
  11.         printLine(line);
  12.     }
  13.         public static String flip(String line) {
  14.             char[] chars = new char[line.length()];
  15.             for(int i = line.length() - 1; i >= 0; i-- ) {
  16.                     chars[line.length() - i - 1] = line.charAt(i);
  17.             }
  18.                 String flipLine = new String(chars);
  19.                 System.out.print(flipLine);
  20.                 return flipLine;
  21.         }
  22.  
  23.             public static void printLine(String line) {
  24.                 System.out.println();
  25.                 System.out.print(line);
  26.             }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement