你所说的正方形输出是指矩形输出吧,下面是完整代码:
十载的双城网站建设经验,针对设计、前端、开发、售后、文案、推广等六对一服务,响应快,48小时及时工作处理。成都全网营销的优势是能够根据用户设备显示端的尺寸不同,自动调整双城建站的显示方式,使网站能够适用不同显示终端,在浏览器中调整网站的宽度,无论在任何一种浏览器上浏览网站,都能展现优雅布局与设计,从而大程度地提升浏览体验。创新互联从事“双城网站设计”,“双城网站推广”以来,每个客户项目都认真落实执行。
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个偶数
{System.out.println();}
}
}
}
运行结果图:
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 函数入口
for(int i = 0; i = 100; i += 2) { // 从0开始,每隔一个数(也就是自加2:i += 2)执行一次输出
System.out.print(i + " "); // 输出当前偶数并在后边加一个空格便于清晰显示
}
}
}
java的研发我不清楚了 (我c#)
大概是这样的 让用户输入的同时 判断下就行 如果是偶数 保存在字符串里面就行了
string sum="偶数是:";
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之间的偶数和”代码如下:
Private Sub Command1_Click()Dim i As IntegerDim s As Integers = 0For i = 2 To 100 Step 2 s = s + iNext iPrint "2到100的所有偶数和是:"; 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的所有偶数和是:"; 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的所有偶数和是:"; 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的所有偶数和是:"; 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 "奇数和为" sum1Print "偶数和为" 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("请输入第"+(i+1)+"位整数:");
a[i] = sc.nextInt();//只能录入整数
if (a[i]%2==0) {
o+=","+a[i];
}
}
System.out.println("偶数为:"+o.substring(1));
System.out.println("录入数组为:"+Arrays.toString(a));
}