Java第一次实训

 1 package com.wsy.work;
 2 
 3 public class JudgeNumber {
 4 
 5     public static void main(String[] args) {
 6         int a = 5;
 7         if(a % 2 == 0)
 8         {
 9             System.out.println(a+"是偶数");
10         }
11         else
12         {
13             System.out.println(a+"是奇数");
14         }
15 
16     }
17 
18 }
 1 package com.wsy.work;
 2 import java.math.BigDecimal;
 3 import java.util.Scanner;
 4 public class Circle {
 5 
 6     public static void main(String[] args) {
 7         BigDecimal PI  = new BigDecimal("3.14");
 8         Scanner in = new Scanner(System.in);
 9         System.out.print("请输入圆的半径:");
10         BigDecimal ridius = new BigDecimal(in.nextLine());
11         BigDecimal s = ridius.multiply(ridius).multiply(PI);
12         System.out.println("圆的面积为:"+s);
13         in.close();
14     }
15 
16 }
 1 package com.wsy.work;
 2 import java.util.Scanner;
 3 public class EncryptionDevice {
 4 
 5     public static void main(String[] args) {
 6         Scanner in = new Scanner(System.in);
 7         int number = Integer.parseInt(in.nextLine());
 8         double result = (number*10+5)/2+3.14159;
 9         System.out.println("加密结果为:"+result);
10     }
11 
12 }
 1 package com.wsy.work;
 2 
 3 public class Work4 {
 4 
 5     public static void main(String[] args) {
 6         final int CHICKEN = 100;
 7         final int MONEY = 100;
 8         for(int i = 0; i<=20; i++)
 9         {
10             for(int j = 0; j<=33; j++)
11             {
12                 for(int k = 0; k<=300; k=k+3)
13                 {
14                     if(i*5+j*3+k/3 == MONEY && i+j+k == CHICKEN)
15                     {
16                         System.out.println("公鸡:"+i);
17                         System.out.println("母鸡:"+j);
18                         System.out.println("公鸡:"+k);
19                         System.out.println("==================================================");
20                     }
21                 }
22                 
23             }
24             
25         }
26     }
27 
28 }
 1 package com.wsy.work;
 2 
 3 public class Work5 {
 4 
 5     public static void main(String[] args) {
 6         int number;
 7         int count = 0;
 8         for(int i = 1; i<=4; i++)
 9         {
10             for(int j =1; j<=4; j++)
11             {
12                 for(int k = 1; k<=4; k++)
13                 {
14                     if(i != j && i != k && j!=k)
15                     {
16                         count++;
17                         number = i*100+j*10+k;
18                         System.out.println(number);
19                     }
20                 }
21                 
22             }
23             
24         }
25         System.out.println("======================================================");
26         System.out.println("不重复的数字总共有:"+count+"个");
27         
28     }
29 
30 }
 1 package com.wsy.work;
 2 import java.util.Scanner;
 3 public class IsPrime {
 4 
 5     public static void main(String[] args) {
 6         boolean isPrime = true;
 7         Scanner in = new Scanner(System.in);
 8         int number = Integer.parseInt(in.nextLine());
 9         if(number == 1)
10         {
11             isPrime = false ;
12         }
13         for(int i = 2; i<=Math.sqrt(number); i++)
14         {
15             if(number % i ==0)
16             {
17                 isPrime = false ;
18                 break;
19             }
20         }
21         if(isPrime)
22         {
23             System.out.println(number+"是素数");
24         }
25         else
26         {
27             System.out.println(number+"不是素数");
28         }
29         in.close();
30     }
31 
32 }            
posted @ 2019-04-03 15:40  oops_w  阅读(255)  评论(1)    收藏  举报