Reverse a string in Java

前端 未结 30 2585
礼貌的吻别
礼貌的吻别 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 14:08

    public void reverString(){
    System.out.println("Enter value");
    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
     try{
    
      String str=br.readLine();
      char[] charArray=str.toCharArray();
      for(int i=charArray.length-1; i>=0; i--){
       System.out.println(charArray[i]);
      }
      }
       catch(IOException ex){
      }
    

提交回复
热议问题