zoukankan      html  css  js  c++  java
  • java练习题:解一元二次方程、判断闰年、判断标准身材、三个数取最大值

    1.解一元二次方程

    注:求根公式为(-b+根号德尔塔)/2a,(-b-根号德尔塔)/2a

                    Scanner sc=new Scanner(System.in);
    		System.out.println("输入a:");
    		double a=sc.nextFloat();
    		System.out.println("输入b:");
    		double b=sc.nextFloat();
    		System.out.println("输入c:");
    		double c=sc.nextFloat();
    		double delta=b*b-4*a*c,x1,x2;
    		if(delta>0){
    			x1=(-b+Math.sqrt(delta))/(2*a);
    			x2=(-b-Math.sqrt(delta))/(2*a);
    			System.out.println("方程的实根为:x1="+x1+","+"x2="+x2);
    		}
    		else if(delta==0){
    			x1=(-b+Math.sqrt(delta))/(2*a);
    			x2=x1;
    			System.out.println("方程的实根为:x1=x2="+x1);
    		}
    		else if(delta<0){
    			System.out.println("方程无实根");
    			}        
    

    2.判断闰年

    注:闰年是能被400整除或者能被4整除不能被100整除的年份

                    System.out.println("输入一个年份");
    		Scanner sc=new Scanner(System.in);
    		long a=sc.nextLong();
    		if(a%400==0){
    			System.out.println("闰年");
    			
    		}
    		else if(a%4==0&&a%100!=0){
    			System.out.println("闰年");
    		}
    		else {
    			System.out.println("平年");
    		}                
    

    3.判断是否为标准体重

    注:

    标准体重的含义:身高-体重(kg)与100(女士为110)相减,得出的差大于3的为偏瘦,小于-3的为偏胖,在-3和3之间的为标准。

                    Scanner sc=new Scanner(System.in);
    		System.out.println("请输入性别(男或女):");
    		String sex=sc.next();
    		System.out.println("请输入身高:");
    		int height=sc.nextInt();
    		System.out.println("请输入体重(kg):");
    		int weight=sc.nextInt();
    		int a=height-weight;
    		if(sex.equals("男")){
    			if(a-100>=-3&&a-100<=3){
    				System.out.println("标准体重");
    			}
    			else if(a-100>3){
    				System.out.println("偏胖");				
    			}
    			else if(a-100<3){
    				System.out.println("偏瘦");
    			}
    		}
    		else if(sex.equals("女")){
    			if(a-110>=-3&&a-110<=3){
    				System.out.println("标准体重");
    			}
    			else if(a-110>3){
    				System.out.println("偏胖");
    			}
    			else if(a-110<-3){
    				System.out.println("偏瘦");
    			}
    		}
    

    4.三个数取最大值

                    System.out.println("输入三个数字:");
    		Scanner sc=new Scanner(System.in);
    		System.out.println("输入第一个数");
    		long a=sc.nextLong();
    		System.out.println("输入第二个数");
    		long b=sc.nextLong();
    		System.out.println("输入第三个数");
    		long c=sc.nextLong();
    		long big=a>b?a:b;
    			big=big>c?big:c;
    		System.out.println("最大的数是:"+big);
    

      

  • 相关阅读:
    RobotFrameWork(一)robotfamework(python版)及Ride在windows安装
    Sql日期时间格式转换[zhuan]
    SQL query
    WPF窗体视图中绑定Resources文件中字符串时,抛出:System.Windows.Markup.StaticExtension
    Power Map 更新日志
    球面墨卡托(Spherical Mercator)
    TPL(Task Parallel Library)多线程、并发功能
    WPF:保存窗口当前状态截图方法
    dynamic关键字
    Error: Cannot Determine the location of the VS common tools folder
  • 原文地址:https://www.cnblogs.com/jonsnow/p/6198630.html
Copyright © 2011-2022 走看看