導航:首頁 > 編程語言 > java1到100奇數

java1到100奇數

發布時間:2025-09-23 17:06:51

❶ 在java中 列印1--100的奇數 每行10個 數字右對齊

for (int i = 1; i < 100; i+=2) {
if(i < 10){
System.out.print(" "+i+"\t");
} else{
System.out.print(i+"\t");
}
if((i+1)%20 == 0){
System.out.println();
}
}

❷ 編寫java程序,分別應用while語句、do-while語句,求出100以內所有奇數的和

while

int i=1;

int result=0;

while(i<=100){

result+=i;

i+=2;

}

System.out.println("100內奇數和為:"+result);


do{}while{}


int i=1;

int result=0;

do {

result+=i;

i+=2;


}while (i<=100);

System.out.println("100內奇數和為:"+result);

❸ 如何用java輸出1到100之間的奇數呢

packagesrc;
publicclassTest{
publicTest(){
//TODOAuto-generatedconstructorstub
}
/**
*@paramargs
*/
publicstaticvoidmain(String[]args){
//TODOAuto-generatedmethodstub
//輸出偶數
for(inti=1;i<=100;i++){
i++;
System.out.print(i);
System.out.print(" ");
}
//輸出奇數
for(inti=0;i<100;i++){
i++;
System.out.print(i);
System.out.print(" ");
}
}
}

閱讀全文

與java1到100奇數相關的資料

熱點內容
單片機二極體c語言 瀏覽:397
python正則字母和符號 瀏覽:166
打開一個文件夾總是卡 瀏覽:207
bat源碼替換 瀏覽:665
java1到100奇數 瀏覽:517
小吃pdf 瀏覽:506
微信收藏文件夾的密碼 瀏覽:339
phpmysql全文索引 瀏覽:999
一台電腦怎麼升級伺服器 瀏覽:516
魅族pro6s伺服器地址 瀏覽:520
php項目架構 瀏覽:868
java語言程序設計第八版基礎篇 瀏覽:636
swf文件怎麼轉換為pdf 瀏覽:947
cad加密管理 瀏覽:169
男朋友程序員涉嫌詐騙罪 瀏覽:609
java怎麼導入文件 瀏覽:971
電腦上怎麼二維碼安裝app 瀏覽:197
c語言不用編譯就能識別嗎 瀏覽:990
java線程start 瀏覽:560
linux編譯器vi 瀏覽:19