大家好,又见面了,我是你们的朋友全栈君。
import java.util.Scanner;
public class number {
public static void main(String[] args) {
int i = 0;
System.out.println("1.3-100 2.任意两数 3.最大十个和最小十个");
Scanner sc = new Scanner(System.in);
i = sc.nextInt();
switch (i) {
case 1:
isprime();
break;
case 2:
isprime1();
break;
case 3:
isprime2();
break;
}
}
public static void isprime() {
int n;
int i = 2;
int m = 0;
for (n = 3; n >= 3 && n <= 100; n++) {
int j = 0;
if (n % 2 == 0)
j = 1;
for (i = 2; i <= Math.sqrt(n); i++) {
if (n % i == 0)
j = 1;
}
if (j == 0) {
m++;
System.out.print(n + "\t");
if (m % 5 == 0)
System.out.println();
}
}
System.out.println();
}
public static void isprime1() {
System.out.println("请输入两个整数:");
Scanner sc = new Scanner(System.in);
int num1, num2;
System.out.println("number1:");
num1 = sc.nextInt();
System.out.println("number2:");
num2 = sc.nextInt();
int n;
int i = 2;
int m = 0;
for (n = num1; n >= num1 && n <= num2; n++) {
int j = 0;
if (n % 2 == 0)
j = 1;
for (i = 2; i <= Math.sqrt(n); i++) {
if (n % i == 0)
j = 1;
}
if (j == 0) {
m++;
System.out.print(n + "\t");
if (m % 5 == 0)
System.out.println();
}
}
}
public static void isprime2() {
Scanner sc = new Scanner(System.in);
System.out.println("请输入两个整数:");
int num1, num2;
System.out.println("number1:");
num1 = sc.nextInt();
System.out.println("number2:");
num2 = sc.nextInt();
System.out.println("十个最小:");
int n;
int i = 2;
int m = 0;
int k = 0;
int a[] = new int[100];
for (n = num1; n >= num1 && n <= num2; n++) {
int j = 0;
if (n % 2 == 0)
j = 1;
for (i = 2; i <= Math.sqrt(n); i++) {
if (n % i == 0)
j = 1;
}
if (j == 0) {
m++;
a[m] = n;
if (m <= 10)
System.out.print(a[m] + "\t");
}
}
System.out.println();
System.out.println("十个最大:");
for (k = m - 10; k <= m; k++) {
System.out.print(a[k] + "\t");
}
}
}
转载于:https://www.cnblogs.com/jhl1234/p/9787271.html
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/107255.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...