Reverse a string in Java

前端 未结 30 2594
礼貌的吻别
礼貌的吻别 2020-11-21 13:12

I have \"Hello World\" kept in a String variable named hi.

I need to print it, but reversed.

How can I do this? I understand there

30条回答
  •  离开以前
    2020-11-21 13:59

    System.out.print("Please enter your name: ");
    String name = keyboard.nextLine();
    
    String reverse = new StringBuffer(name).reverse().toString();
    String rev = reverse.toLowerCase();
    System.out.println(rev);
    

    I used this method to turn names backwards and into lower case.

提交回复
热议问题