你所說的正方形輸出是指矩形輸出吧,下面是完整代碼:
十載的雙城網(wǎng)站建設(shè)經(jīng)驗(yàn),針對(duì)設(shè)計(jì)、前端、開發(fā)、售后、文案、推廣等六對(duì)一服務(wù),響應(yīng)快,48小時(shí)及時(shí)工作處理。成都全網(wǎng)營(yíng)銷的優(yōu)勢(shì)是能夠根據(jù)用戶設(shè)備顯示端的尺寸不同,自動(dòng)調(diào)整雙城建站的顯示方式,使網(wǎng)站能夠適用不同顯示終端,在瀏覽器中調(diào)整網(wǎng)站的寬度,無論在任何一種瀏覽器上瀏覽網(wǎng)站,都能展現(xiàn)優(yōu)雅布局與設(shè)計(jì),從而大程度地提升瀏覽體驗(yàn)。創(chuàng)新互聯(lián)從事“雙城網(wǎng)站設(shè)計(jì)”,“雙城網(wǎng)站推廣”以來,每個(gè)客戶項(xiàng)目都認(rèn)真落實(shí)執(zhí)行。
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個(gè)偶數(shù)
{System.out.println();}
}
}
}
運(yùn)行結(jié)果圖:
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");
}
}
}
}
}
class Print { // java 類的聲明
public static void main(String[] args) { // main 函數(shù)入口
for(int i = 0; i = 100; i += 2) { // 從0開始,每隔一個(gè)數(shù)(也就是自加2:i += 2)執(zhí)行一次輸出
System.out.print(i + " "); // 輸出當(dāng)前偶數(shù)并在后邊加一個(gè)空格便于清晰顯示
}
}
}
java的研發(fā)我不清楚了 (我c#)
大概是這樣的 ?讓用戶輸入的同時(shí) ?判斷下就行 如果是偶數(shù) 保存在字符串里面就行了
string?sum="偶數(shù)是:";
for(int?i=0;?i10;?i++)
{
if(putinNum%2==0)
{
sum+=putinNum.toString()+",";
}
}
//輸出sum就行了
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
public static void main(String[] args) {
int a[] = new int[5];
Scanner sc = new Scanner(System.in);
String o = "";
for (int i = 0; i a.length; i++) {
System.out.print("請(qǐng)輸入第"+(i+1)+"位整數(shù):");
a[i] = sc.nextInt();//只能錄入整數(shù)
if (a[i]%2==0) {
o+=","+a[i];
}
}
System.out.println("偶數(shù)為:"+o.substring(1));
System.out.println("錄入數(shù)組為:"+Arrays.toString(a));
}