用java代碼實現

 用java代碼實現
(1)珠穆朗瑪峯高度爲8848米,有一張足夠大的紙,厚度爲0.001米。
(2)請問,我摺疊多少次,能夠折成珠穆朗瑪峯的高度
/**
* @author 18269 * @date 2019/10/31 18:57:04 * @description */ public class Demo5 { public static void main(String[] args) { // TODO Auto-generated method stub //定義一個統計變量,默認值是0 int count = 0; //爲了簡單,我把0.01變成1,同理8848就變成了884800 int end = 884800; int start = 1; while(start<end) { //只要每次增長的後的厚度沒有超過珠穆朗瑪峯的高度就摺疊,變量++ count++; //摺疊一次厚度是之前的2倍。 start *= 2; System.out.println("第"+count+"次厚度是"+start); } //輸出統計變量。 System.out.println("要疊"+count+"次"); } /**
 * @author 18269 * @date 2019/10/31 19:09:44 * @description */
public class Demo_6 { public static void main(String[] args) { /* 分析如下需求,並用代碼實現: (1)打印1到100以內的整數,但數字中包含9的要跳過 (2)每行輸出5個知足條件的數,之間用空格分隔*///定義一個變量,用來記錄知足條件數的個數
        int count = 0; for(int i = 1;i <= 100;i++){ if(i % 10 == 9 || i / 10 == 9){ continue; } count++; System.out.print(i + " "); if(count % 5 == 0){//不用從新置換0,經過取餘解決不超過五的問題
 System.out.println(); } } } }
相關文章
相關標籤/搜索