首页 > 编程语言 > 详细

Java学习笔记11

时间:2016-12-23 22:08:58      阅读:185      评论:0      收藏:0      [点我收藏+]
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);
    }
}

 

Java学习笔记11

原文:http://www.cnblogs.com/datapool/p/6216106.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!