zoukankan      html  css  js  c++  java
  • 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);
        }
    }
  • 相关阅读:
    !!!!Linux系统开发 系列 4 进程资源 环境 fork()子进程 wait() waitpid()僵尸 孤儿进程
    linux运维工程师
    C# CSGL
    C# 中的"yield"使用
    C#语法糖
    VS2017下Git的使用
    Oracle数据类型与.NET中的对应关系
    Java 8 Stream
    Java 8 默认方法
    Java 8 函数式接口
  • 原文地址:https://www.cnblogs.com/datapool/p/6216106.html
Copyright © 2011-2022 走看看