Java教程

java 3.20

本文主要是介绍java 3.20,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

1    

package fjh;

import java.util.Scanner;

public class zhc {
    private static int x,y;

    public static void main(String[] args) {
        System.out.println("请输入x:");
        Scanner scanner=new Scanner(System.in);
         x= scanner.nextInt();
         see();
    }
    public  static void see(){

        y=x*x+3*x+2;
        System.out.println(y);
    }
}

2

package fjh;

import java.util.Scanner;

public class zhc3 {
    public static void main(String[] args) {
        int a,b,c,d;
        System.out.println("请输入一个三位数:");
        Scanner scanner =new Scanner(System.in);
        a=scanner.nextInt();
        b=a%10;
        c=a/10%10;
        d=a/100;
        System.out.println("个位:"+b+"十位:"+c+"百位:"+d);

    }
}

3

package fjh;

import java.util.Scanner;

public class zhc2 {
    public static void main(String[] args) {
        float r;
        double s,x;
        System.out.println("请输入圆的半径r:");
        Scanner scanner=new Scanner(System.in);
        r=scanner.nextFloat();
        s=3.14*r*r;
        x=2*3.14*r;
        System.out.println("圆的面积"+s+"圆的周长"+x);


    }
}

4

package fjh;

import java.util.Scanner;

public class zhc4 {
    public static void main(String[] args) {
        int a;
        String s,y,x;
        y="男性";
        x="女性";
        Scanner scanner =new Scanner(System.in);
         s=scanner.next();
         a=scanner.nextInt();
         if (s.equals(y)){
                 if (a<=60)
                     System.out.println("输血量为250毫升");
                 else System.out.println("输血量为300毫升");

         }
         else if (s.equals(x)){

             if (a<=50) System.out.println("输血量为200毫升");
             else System.out.println("输血量为250毫升");
         }

    }

}

 

 5

package fjh;

import java.util.Scanner;

public class zhc6 {
    public static void main(String[] args) {
        String a,r,y;
        int s,h,w=0;
        r="硬座";
        y="硬卧";
        System.out.println("请输入,票的类型 年龄,和身高,:");
        Scanner scanner =new Scanner(System.in);
         a=scanner.next();
         s=scanner.nextInt();
         h=scanner.nextInt();



        if (s<18){
            if (a.equals(r)){w=100;
                  if (h<120) w=0;
            else if (h>=120&h<150) w=w/2;}
            else {w=190;
                if (h<120) w=w-50;
                else if (h>=120&h<150) w=w-50;

            }

        }else {if (a.equals(r))w=100;
            else w=190;

        }

        System.out.println("票价为:"+w);

    }
}

 

 6

package fjh;

import java.util.Scanner;

public class zhc5 {
    public static void main(String[] args) {
        int a;
        System.out.println("请输入空调的温度:");
        Scanner scanner=new Scanner(System.in);
        a=scanner.nextInt();
        if (a>26)
            System.out.println("开启制冷模式");
        else if(a<10) System.out.println("开启制热模式");
        else System.out.println("开启送风模式");
    }
}

 

 7

package fjh;

import java.util.Scanner;

public class zhc7 {
    public static void main(String[] args) {

       double a,  b,d,u,l=0,x;
        System.out.println("请输入用电额度:");
        Scanner scanner=new Scanner(System.in);
         a=scanner.nextDouble();
         if (a<=150) {b=0.4463;
         l=a*b;
         }
         else if (a>150&a<=400) {d=0.4663;  l=((a-150)*d)+150*0.4463;

         }
         else if (a>=401) {u=0.5663; l=((a-400)*u+(a-150)*0.4663+(150*0.4463));

         }

        System.out.println("你的用电量为"+a+"电费为"+l);

    }
}

 

 8

package fjh;

import java.util.Scanner;

public class zhc8 {
    public static void main(String[] args) {
        System.out.println("请输入月份");
        int a;
        Scanner scanner =new Scanner(System.in);
        a=scanner.nextInt();
        switch (a){
            case 1:
            case 2:
            case 3:
                System.out.println("春天");break;
            case 4:
            case 5:
            case 6:
                System.out.println("夏天");break;
            case 7:
            case 8:
            case 9:
                System.out.println("秋天");break;
            case 10:
            case 11:
            case 12:
                System.out.println("冬天");break;

        }
    }
}

 

 9

package fjh;

public class zhc9 {
    public static void main(String[] args) {
        int a=560,b,c;
         b=560/60;
         c=560%60;
        System.out.println("560分钟是:"+b+"小时"+c+"分钟");

    }
}

 

 

 10

package fjh;

import java.util.Scanner;

public class zhc10 {
    public static void main(String[] args) {
        //输入三个整数A、B和C,将它们交换(即A的值给B,B的值给C,C的值给A)后输出A、B和C。
        int  a,b,c,t,x;
        System.out.println("输入三个数ABC:");
        Scanner scanner =new Scanner(System.in);
        a=scanner.nextInt();
        b=scanner.nextInt();
        c=scanner.nextInt();
        System.out.println("没更换之前这三个数是"+"A:"+a+ "B:"+b+ "C:"+c);
        t=b;
        b=a;
        x=c;
        c=t;
        a=c;
        System.out.println("更换之后这三个数是"+"A:"+a+"B:"+b+  "C:"+c);


    }
}

 

 

这篇关于java 3.20的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!