zoukankan      html  css  js  c++  java
  • 第一次实训作业

    判断奇偶数:
    1 package javaApplication; 2 import java.util.*; 3 public class Odevity 4 { 5 public static void main(String[] args) 6 { 7 Scanner scanner=new Scanner(System.in); 8 int x; 9 System.out.println("请输入一个数:"); 10 x=scanner.nextInt(); 11 if(x%2==0) 12 { 13 System.out.println("这个数是偶数"); 14 } 15 else 16 { 17 System.out.println("这个数是奇数"); 18 } 19 scanner.close(); 20 } 21 }

    求圆的面积:

    1 package javaApplication;
     2 import java.util.*;
     3 public class Circle1 
     4 {
     5     final static double PI=3.14159;
     6     public static void main(String[] args)
     7     {
     8         Scanner scanner=new Scanner(System.in);
     9         int r;
    10         double s=0;
    11         System.out.println("请输入半径:");
    12         r=scanner.nextInt();
    13         
    14         s=PI*r*r;
    15         System.out.printf("面积为:%.2f",s);
    16         scanner.close();    
    17     }
    18 }

    加密处理:

     1 package javaApplication;
     2 import java.util.Scanner;
     3 public class Encipher
     4 {
     5     public static void main(String[] args)
     6     {
     7         Scanner scanner=new  Scanner(System.in);
     8         System.out.println("请输入要加密的数:");
     9         int x=scanner.nextInt();
    10         int y=(int)((x*10+5)/2+3.14159);
    11         System.out.println("加密后为:"+y);
    12         scanner.close();
    13     }
    14 }

    公鸡,母鸡,小鸡问题:

     1 package javaApplication;
     2 
     3 public class Chicken
     4 {
     5     public static void main(String[] args) 
     6     {
     7         System.out.println("可能的方案为:");
     8         for(int i=0;i<20;i++) //i表示公鸡
     9         {
    10             for(int j=0;j<33;j++) //j表示母鸡
    11             {
    12                 for(int l=0;l<100;l+=3) //l表示小鸡
    13                 {
    14                     if((i*5+j*3+l/3.0==100)&&(j+i+l==100))
    15                     {
    16                         System.out.printf("公鸡%d只   母鸡%d只   小鸡%d只",i,j,l);
    17                         System.out.println();
    18                     }
    19                 }
    20             }
    21         }    
    22     }
    23 }

    不同且不重复的三位数:

    1 package javaApplication;
     2 
     3 public class ThreeDigitNumber 
     4 {
     5     public static void main(String[] args)
     6     {
     7         
     8         int n=0;
     9         for(int i=1;i<=4;i++) //i表示百位
    10         {
    11             for(int j=1;j<=4;j++) //j表示十位
    12             {
    13                 if(i==j)
    14                 {
    15                     continue;
    16                 }
    17                 for(int l=1;l<=4;l++) //l表示各个位
    18                 {
    19                     if(l==j||l==i) 
    20                     {
    21                         continue;
    22                     }
    23                     n++;
    24                     System.out.print((i*100+j*10+l)+" ");
    25                     if(n%6==0)
    26                     {
    27                         System.out.println();
    28                     }    
    29                 }
    30             }
    31         }
    32         System.out.println("共有"+n+"个不同的三位数。");    
    33     }
    34 
    35 }
  • 相关阅读:
    JavaScript数组操作
    cxf-rs 和 swagger 的点
    cxf-rs 、spring 和 swagger 环境配置切换【github 有项目】
    (二)swagger-springmvc
    (二)spring-mvc-showcase 和 swagger-springmvc 的恩恩怨怨
    svn 创建tag
    swagger 入门
    jax-rs
    swagger core 和 swagger ui 如何关联【窥探】
    配置 struts2 时掉进 web.xml 的坑
  • 原文地址:https://www.cnblogs.com/pamper/p/10996771.html
Copyright © 2011-2022 走看看