华为机试:字符逆序

和字符串反转类似,详见http://www.cnblogs.com/zdtiio/p/7570806.html

题目描述

将一个字符串str的内容颠倒过来,并输出。str的长度不超过100个字符。 如:输入“I am a student”,输出“tneduts a ma I”。

 

 

 
输入参数:

inputString:输入的字符串

 


返回值:

输出转换好的逆序字符串

 

 

输入描述:

输入一个字符串,可以有空格

输出描述:

输出逆序的字符串

示例1

输入

I am a student

输出

tneduts a ma I

 

Java:

 1 import java.util.Scanner;
 2 
 3 public class Main {
 4     
 5     public static void main(String[] args) {
 6         Scanner sc=new Scanner(System.in);
 7         while(sc.hasNext()){
 8             String s = sc.nextLine();
 9             for(int i = s.length() - 1; i >= 0; i--){
10                 System.out.print(s.charAt(i));
11             }
12             System.out.println();
13         }
14         sc.close();
15     }
16     
17 }

 

posted @ 2017-09-22 04:32  zdtiio  阅读(268)  评论(0编辑  收藏  举报