#16361: 想請問為何測試不會對


a0953143887@gmail.com (林柏宇)

學校 : 不指定學校
編號 : 80105
來源 : []
最後登入時間 :
2018-05-22 23:49:03
a038. 數字翻轉 | From: [111.251.205.29] | 發表日期 : 2018-12-24 00:44

import java.util.Scanner;

public class A038 {

      public static void main(String[] args) {
            // TODO Auto-generated method stub
           Scanner sc=new Scanner(System.in);
           while(sc.hasNext()) {
                String s=sc.nextLine();
                for(int i=s.length()-1;i>=0;i--) {
                     if(s.charAt(s.length()-1)=='0') {
                           if(s.length()==1) {
                                 System.out.print("0");
                            }
                           continue;
                      }
                     System.out.print(s.charAt(i));
              }System.out.println();
           }
     }

}

 

 

 
#16362: Re:想請問為何測試不會對


a0970580085@gmail.com (/)

學校 : 義守大學
編號 : 74647
來源 : [125.229.235.114]
最後登入時間 :
2023-08-30 17:36:04
a038. 數字翻轉 | From: [61.221.174.229] | 發表日期 : 2018-12-24 13:57

import java.util.Scanner;

public class A038 {

      public static void main(String[] args) {
            // TODO Auto-generated method stub
           Scanner sc=new Scanner(System.in);
           while(sc.hasNext()) {
                String s=sc.nextLine();
                for(int i=s.length()-1;i>=0;i--) {
                     if(s.charAt(s.length()-1)=='0') {
                           if(s.length()==1) {
                                 System.out.print("0");
                            }
                           continue;
                      }
                     System.out.print(s.charAt(i));
              }System.out.println();
           }
     }

}

 

 

最後一位數是0的話就被你continue掉了,執行不到System.out.print(s.charAt(i));這段。


 
ZeroJudge Forum