标签:
package hello;
import java.util.Scanner;
public class hello {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// int n = in.nextInt();
// int isPrime = 1;
// int count = 0;
// int i;
// 判断一个数 是否是 素数 (只能被 1 和本身 整除)
// 输出 100 以内的 素数
for (int n=2; n<100; n++)
{
int isPrime = 1;
for( int i=2;i<n;i++)
{
if(n % i == 0){
isPrime = 0;
break;
}
}
if(isPrime == 1){
System.out.println(n+"是素数");
}
}
// else{
// System.out.println(n+"不是素数");
// }
}
}
---------------------------------------------------------------
package hello;
import java.util.Scanner;
public class hello {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
for(int i=1; i<=9; i++){
for(int j=1; j<=i; j++){
System.out.print(i * j);
System.out.print(" ");
}
System.out.println();
}
}
}
-----------------------------------------------------
package hello;
import java.util.Scanner;
public class hello {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// 输出前 50 个 素数
int count = 0;
// int n = in.nextInt();
for(int n=2; count<=50;n++){
int isPrime = 1;
for(int i=2; i<n; i++){
if(n%i == 0){
isPrime = 0;
break;
}
}
if(isPrime == 1){
System.out.println(n+"是素数");
count ++;
}
}
}
}
--------------------------------------------------------------
package hello;
import java.util.Scanner;
public class hello {
public static void main(String[] args) {
// 1 角、2角、5角 -- 10元
OUT:
for(int i=1; i<=100; i++){
for(int j=1; j<=50; j++){
for(int k=1; k<=20; k++){
if(i+2*j+5*k == 100){
System.out.println(i+"个 1角,"+j+"个2角,"+k+"个5角");
break OUT;
}
}
}
}
}
}
----------------------------------------
标签:
原文地址:http://www.cnblogs.com/jy627625/p/5722521.html