真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

java代碼輸出偶數(shù) java求偶數(shù)和代碼

用JAVA編寫程序:輸入20個整數(shù)存入數(shù)組中,輸出其中的偶數(shù)及偶數(shù)之和

public static void main(String[] args) {

創(chuàng)新互聯(lián)公司主營龍山網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營網(wǎng)站建設(shè)方案,APP應(yīng)用開發(fā),龍山h5重慶小程序開發(fā)搭建,龍山網(wǎng)站營銷推廣歡迎龍山等地區(qū)企業(yè)咨詢

int array[] = new int[20];

int result = 0;

ListInteger list = new ArrayListInteger();

System.out.println("請輸入20個整數(shù):");

Scanner sc = new Scanner(System.in);

for (int i = 0; i 20; i++) {

array[i] = sc.nextInt();

if(array[i] % 2 == 0) {

list.add(array[i]);

result += array[i];

}

}

System.out.println("偶數(shù)為:");

for (int i = 0; i list.size(); i++) {

System.out.println(list.get(i));

}

System.out.println("偶數(shù)和為:" + result);

}

Java怎么編程輸出1-100間的偶數(shù)?

for(int i=0;i;i+){

if(i%2=0){

System.out.println(i);}

}

一、按鈕“求2到100之間的偶數(shù)和”代碼如下:

Private Sub Command1_Click()Dim i As IntegerDim s As Integers = 0For i = 2 To 100 Step 2 s = s + iNext iPrint "2到100的所有偶數(shù)和是:"; sEnd Sub

二、按鈕“方法2”代碼如下:

Private Sub Command2_Click()Dim i As IntegerDim s As Integers = 0For i = 2 To 100If i Mod 2 = 0 Then s = s + iEnd IfNext iPrint "2到100的所有偶數(shù)和是:"; sEnd Sub

三、按鈕“方法3”代碼如下:

Private Sub Command3_Click()Dim i As IntegerDim s As Integers = 0i = 2DoIf i Mod 2 = 0 Then s = s + iEnd Ifi = i + 1Loop Until i 100Print "2到100的所有偶數(shù)和是:"; sEnd Sub

四、按鈕“方法4”代碼如下:

Private Sub Command4_Click()Dim i As IntegerDim s As Integers = 0i = 2Dos = s + ii = i + 2Loop Until i 100Print "2到100的所有偶數(shù)和是:"; sEnd SubPrivate Sub Command2_Click()Dim i, sum1, sum2 As Integersum1 = 0sum2 = 0For i = 1 To 100If i Mod 2 = 1 Thensum1 = sum1 + iElsesum2 = sum2 + iEnd IfNext iPrint "奇數(shù)和為" sum1Print "偶數(shù)和為" sum2End Sub

java循環(huán)語句輸出0到40的偶數(shù)并用正方形輸出

你所說的正方形輸出是指矩形輸出吧,下面是完整代碼:

public??class??Output

{

public?static?void?main(String?[]args)//主方法

{

int?i;

int?count=0;

for(i=0;i=40;i+=2)??

{

count++;

System.out.printf("%-4d",i);?

if(count%7==0)???//每行顯示7個偶數(shù)

{System.out.println();}

}

}

}

運行結(jié)果圖:

JAVA編寫程序,輸出100到1000間的所有偶數(shù),并要求每行輸出“10個數(shù)字

public?class?Test?{

public?static?void?main(String[]?args)?{

int?count?=?0;

for?(int?i?=?100;?i?=?1000;?i++)?{

if?(i?%?2?==?0)?{

System.out.print(i?+?"?");

if?(++count?%?10?==?0)?{

System.out.print("\n");

}

}

}

}

}


當(dāng)前文章:java代碼輸出偶數(shù) java求偶數(shù)和代碼
當(dāng)前網(wǎng)址:http://weahome.cn/article/dodddid.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部