Java藍橋杯--基礎練習(7)特殊迴文數

來源:互聯網
上載者:User

標籤:system.in   基礎練習   image   迴文   輸出   imp   條件陳述式   util   set   

關鍵詞:

迴文數 迴圈 條件陳述式 2



題目:

解決方案:

 1 package com.algorithm.java.blueBirdge; 2  3 import java.util.Scanner; 4  5 public class Paliindrome2 { 6     public static void main(String[] args){ 7         Scanner read =new Scanner(System.in); 8         int sum =read.nextInt(); 9         //int sum=0;10         for(int i=10000;i<=999999;i++){11             if (i>=10000 && i<=99999) {12                 //個位13                 int gewei5=i % 10;14                 // 十位15                 int shiwei5=(i % 100) / 10;16                 // 百位17                 int baiwei5=(i/100)%10;18                 // 千位19                 int qianwei5=(i / 1000) % 10;20                 // 萬位21                 int wanwei5=i / 10000;22                 //輸出這樣的五位元23                 if (gewei5== wanwei5 && ((shiwei5) == (qianwei5)  &&  (gewei5+shiwei5+baiwei5+qianwei5+wanwei5==sum))) {24                     //if(){25                         System.out.println(i);26                     //}27 28                 }29             }30 31             //輸出這樣的六位元   999 99932             else{33                 //個位34                 int gewei6=i % 10;35                 // 十位36                 int shiwei6=(i % 100) / 10;37                 // 百位38                 int baiwei6=(i%1000)/100;39                 // 千位40                 int qianwei6=(i/1000)%10;41                 // 萬位42                 int wanwei6=(i / 10000) % 10;43                 //十萬位44                 int shiwanwei6=i / 100000;45 46                 if ((gewei6 == shiwanwei6 && ((shiwei6) == (wanwei6)) && (baiwei6)==qianwei6)   &&   (gewei6+shiwei6+baiwei6+qianwei6+wanwei6+shiwanwei6==sum)) {47                     //if(){48                         System.out.println(i);49                     //}50 51                 }52             }53         }54     }55 }

 

Java藍橋杯--基礎練習(7)特殊迴文數

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.