题解 | #数字颠倒#

字符串反转

http://www.nowcoder.com/practice/e45e078701ab4e4cb49393ae30f1bb04

// import java.util.Scanner;

// 方法一:
// public class Main {
// public static void main(String[] args) {
// Scanner sc = new Scanner(System.in);
// String input = sc.nextLine();
// StringBuilder sb = new StringBuilder();
// for(int i=input.length()-1; i>=0; i--){
// sb.append(input.charAt(i));
// }
// System.out.println(sb.toString());
// }
// }

// 方法二:
import java.util.Scanner;

/**

  • 字符串反转
  • 题目描述
  • 写出一个程序,接受一个字符串,然后输出该字符串反转后的字符串。(字符串长度不超过1000)
  • 输入描述:
  • 输入N个字符
  • 输出描述:
  • 输出该字符串反转后的字符串
  • 示例1
  • 输入abcd
  • 输出dcba
  • /
    public class Main {
    public static void main(String[] args) {
      Scanner scanner = new Scanner(System.in);
      while(scanner.hasNext()){
          String str= scanner.nextLine();
          //将字符串变成char数组再倒序输出
          char[] chars= str.toCharArray();
          for(int i=chars.length-1;i>=0;i--){
              System.out.print(chars[i]);
          }
          System.out.println();
      }
    }
    }
全部评论

相关推荐

owwhy:难,技术栈在嵌入式这块显得非常浅,并且简历有大问题。教育经历浓缩成两行就行了,写什么主修课程,说的不好听这块没人在意,自我评价删了,项目写详细点,最终简历缩成一页。相关技能怎么说呢,有点差了,还写成这么多行
投了多少份简历才上岸
点赞 评论 收藏
分享
03-04 07:14
门头沟学院 C++
何木健一:去啥?你能考虑去就是思想有问题,当然一周到岗一天可以考虑一下😨
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务