1 判断三角形
判断方法
package com.sanjiaoxin; public class PdSjx { int a; int b; int c; boolean flag; public void PanDuan() { if(a+b>c&&a+c>b&&a+c>b) { //判断是否为三角形 flag = true; if((a*a==b*b+c*c)||(b*b==a*a+c*c)||(c*c==a*a+b*b)) { //判断三角形的类型 System.out.println("这是个直角三角形"); }else if((a*a>b*b+c*c)||(b*b>a*a+c*c)||(c*c>a*a+b*b)) { System.out.println("这是个钝角三角形"); }else if(a==b&&a==c) { System.out.println("这是个等边三角形"); }else { System.out.println("这是个锐角三角形"); } }else { flag = false; System.out.println("这不能构成三角形'"); } } }
测试类
package com.sanjiaoxin; import java.util.Scanner; public class Main { static Scanner sc = new Scanner(System.in); public static void main(String[] args) { PdSjx l = new PdSjx(); String answer = null; do { System.out.print("请输入第一条边:"); l.a = sc.nextInt(); System.out.print("请输入第二条边:"); l.b = sc.nextInt(); System.out.print("请输入第三条边:"); l.c = sc.nextInt(); l.PanDuan(); System.out.print("继续吗? y/n:"); answer = sc.next(); }while("y".equals(answer)); System.out.println("谢谢使用"); } }
2.贷款
计算代码
package com.Money; public class JieMoney { double zlx;//总利息 int dkje;//贷款金额 int year;//年限 double myhkje;//每月还款金额 public void Money() { if(year >=0&&year <= 3) { zlx =dkje * 0.0603*year; myhkje = (dkje+zlx) /(year*12); }else if(year <= 5) { zlx =dkje * 0.0613*year; myhkje = (dkje+zlx) /(year*12); }else { zlx =dkje * 0.0639*year; myhkje = (dkje+zlx) /(year*12); } System.out.println("***月供为"+myhkje); } }
测试代码
package com.Money; import java.util.Scanner; public class main { static Scanner sc = new Scanner(System.in); public static void main(String[] args) { JieMoney k = new JieMoney(); System.out.print("请输入贷款金额:"); k.dkje = sc.nextInt(); System.out.print("请选择贷款年限:"); System.out.println("1.3年(36个月)"+" "+"2.5年(60月)"+" "+"3.20年(240个月)"); k.year = sc.nextInt(); k.Money(); } }