• Java学习笔记11


    package welcome;
    
    import java.util.Scanner;
    /*
     * 代数问题:求解2x2线性方程
     */
    
    public class ComputeLinearEquation {
        public static void main(String[] args) {
            Scanner in = new Scanner(System.in);
    
            System.out.print("Enter a, b, c,  d,  e, f: ");
    
            double a = in.nextDouble();
            double b = in.nextDouble();
            double c = in.nextDouble();
            double d = in.nextDouble();
            double e = in.nextDouble();
            double f = in.nextDouble();
    
            double x = 0;
            double y = 0;
    
            if (a * d - b * c != 0) {
                x = (e * d - b * f) / (a * d - b * c);
                y = (a * f - e * c) / (a * d - b * c);
            } else {
                System.out.println("The equation has no solution");
                System.exit(0);
            }
    
            System.out.println("x is " + x + " and y is " + y);
        }
    }
    package welcome;
    
    import java.util.Scanner;
    /*
     * 游戏:学习加法
     */
    public class TestAddition {
        public static void main(String[] args) {
            int a = (int)(Math.random() * 100);
            int b = (int)(Math.random() * 100);
            
            Scanner in = new Scanner(System.in);
            System.out.print("What is " + a + " add " + b + " ? ");
            int guess = in.nextInt();
            
            if(a + b == guess){
                System.out.println("true");
            }else{
                System.out.println("false");
            }
        }
    }
    package welcome;
    
    import java.util.Scanner;
    
    /*
     * 计算一个三角形的周长
     */
    public class ComputeGirth {
        public static void main(String[] args) {
            Scanner in = new Scanner(System.in);
            
            System.out.print("Enter three sides of a triangle: ");
            double a = in.nextDouble();
            double b = in.nextDouble();
            double c = in.nextDouble();
            
            
            double G = 0;
            
            if(a + b > c && a + c > b && b + c > a){
                G = a + b + c;
            }else{
                System.out.println("The input is illegal");
                System.exit(0);
            }
            
            System.out.println("The triangle has a circumference of " + G);
        }
    }
  • 相关阅读:
    Electron踩坑记录
    TypeScript实现设计模式——生成器模式
    在express中使用ES7装饰器构建路由
    微信小程序下载文件(非图片),并校验扩展名。
    防抖与节流
    yarn
    spark
    docker php-fpm中安装GD库
    thinkphp6 多应用路由遇坑记
    CentOS 7 开启SSH远程登录
  • 原文地址:https://www.cnblogs.com/datapool/p/6216106.html
Copyright © 2020-2023  润新知