标签:pre style can put span linear als com out
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); } }
标签:pre style can put span linear als com out
原文地址:http://www.cnblogs.com/datapool/p/6216106.html