Basic Question for new Java Student

后端 未结 4 1743
挽巷
挽巷 2021-01-28 13:01

I am very new to Java and I have no other programming experience. I am struggling with a homework question and I have only gotten so far. I am very sure this question is very s

4条回答
  •  忘掉有多难
    2021-01-28 13:28

    You can try something like below.

    public class BlackBelt8 {
    
    
     public static void main(String[] args) {
    
      System.out.println(reverse(5433));
    
     }
     public static int reverse(int x){
      String aString = String.valueOf(x);
    
      StringBuilder strBuild = new StringBuilder(aString);
      StringBuilder strReverseBuild = strBuild.reverse();
    
      int resultInt = Integer.parseInt(strReverseBuild.toString());
      return resultInt;
    
     }
    
    }
    

提交回复
热议问题