學習筆記(2)

隨機輸入一個數,判斷它是不是對稱數(迴文數)(如3,121,12321,45254)。不能用字符串庫函數

 

public boolean  symmetry(long n){

       int i,temp; 
       i = n; 
       temp = 0;
       while(i){ 
            temp = temp *10 +i%10;
            i/=10;
        } 
      return (temp == n); 
}

  

發佈了48 篇原創文章 · 獲贊 1 · 訪問量 1779
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章