用java写 输入初值,输出100个不能被3整除的数

2025-01-03 22:42:31
推荐回答(4个)
回答1:

import java.util.Scanner;
public class Test{
public static void main(String[] args){
System.out.println("请输入初值:");
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int j = 0;//换行标志数
for(int i=a;;i++){
if(i%3!=0){
System.out.print(i+" ");
j++;
}
if(j%10==0){//没输出10个数,换行
System.out.println();
}
if(j==100){break;}
}
}
}
希望你喜欢!

回答2:

package com.myDemo;
import java.util.Scanner;
//import java.util.Scanner;
public class DidDemo {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int num = scanner.nextInt();

did(num);
}
public static void did(int num)
{
int count = 0;
int x=1;
for(int i=0;;i++)
{
if(num%3!=0)
{
System.out.println("第"+x+"个数:"+num);
x++;
}
else
{
x++;
}
num++;
count++;
if(count==100)
{
System.out.println("over!");
break;
}
}
}
}

常交流啊亲

回答3:

  这个值是150

  public static void main(String[] args) {
  int count=0;
  for (int i = 1; i <=10000; i++) {
  if(count==100){
  System.out.println(i);
  break;
  }
  if(i%3!=0){
  count++;
  }
  }
  }

回答4:

输初值干什么?