编写JAVA程序,实现输出1--100之间所有不能被7整除的数,并求和   要求:每输出4个数据换行显示


/**
* 输出1--100之间所有不能被7整除的数,并求和   要求:每输出4个数据换旅掘行显示
*/
public static void main(String[] args) {
int sum=0; //和
int j=0;
//乎禅已知次数,用for循环解决该问拆顷核题
for (int i = 1; i <=100; i++)
{
if(i%7==0)
{
continue;
}else
{
System.out.print(" "+i);
}
j++;
if(j%4==0)

{
System.out.println("");
}

sum=sum+i;
}
System.out.println("和为:"+sum);
}
}
public class t2
{
public static void main(String []args)
{
int count=0;
for(int i=1;i<=100;i++)
{
if(i%7!=0)
{
System.out.print(i+"燃如 ");
count++;
}
if(count%4==0)
System.out.println("宽段让慎局");
}
}
}
public class Div {
public static void main(String[] args) {
for (int i = 1, count = 0; i <凯粗渣= 100; i++) {
if (count == 4) {
System.out.println();
count = 0;
}
if (i % 7 != 0) {
count++;
System.out.print(i + "盯悄\凳衫t");
}
}
}
}
给枝正改个代清早码你
public void test() {
int num = 0;
int sum = 0;
for(int i = 0;i <= 100;i ++) {
if(i % 7 != 0) {
num ++;
sum += i;
System.out.print(i + "\t");
if(num % 4 == 0)
System.out.println();
}
}
System.out.println();
System.out.println("猛判sum="+sum);
}
package com.gem.test1;
class Array{
public void print() {
int i[]=new int[100];
int count=0;int sum=0;
for (int j = 0; j <弯握 i.length; j++) {
i[j]=j;
if((i[j]%7)==0){
count++;
sum+=i[j];
System.out.print(i[j]+"桐闹灶\t"局扮);
if (count%4==0) {
System.out.println();
}
}
}
System.out.print(sum);
}
}
public class ArrayDemo {
public static void main(String[] args) {
Array arr=new Array();
arr.print();
}
}
结果:
0 7 14 21
28 35 42 49
56 63 70 77
84 91 98 735