1.例3.1求一元二次方程的根
import java.util.Scanner; public class cjava { public static void main(String[]args) { float a,b,c,x1,x2; Scanner con=new Scanner(System.in); System.out.println("输入a,b,c的值:"); a=con.nextInt(); b=con.nextInt(); c=con.nextInt(); x1=(float)((-b+Math.sqrt(b*b-4*a*c))/(2*a)); x2=(float)((-b-Math.sqrt(b*b-4*a*c))/(2*a)); System.out.println("x1*"+x1); System.out.println("x2*"+x2); }
3.2求三角形面积
package bgio; import java.util.Scanner; import java.lang.*; public class cjava { public static void main(String[]args) { float a,b,c,x1,x2; double s,area; Scanner g=new Scanner(System.in); System.out.println("输入a,b,c的值"); a=g.nextInt(); b=g.nextInt(); c=g.nextInt(); if(a+b>c&&b+c>a&&a+c>b) { s=(a+b+c)/2; area=Math.sqrt(s*(s-a)*(s-b)*(s-c)); System.out.println("area="+area); } else System.out.println("it is not a trilateral!"); } }
3.3判断字符大小写,大写转换为小写,小写不转换
package bgio; import java.util.Scanner; public class cjava { public static void main(String[]args) { char ch; Scanner g=new Scanner(System.in); System.out.println("请输入ch:"); String s; s=g.next(); ch=s.charAt(0); if(ch>='A'&&ch<='Z') { ch+=+32; System.out.println(ch); } else System.out.println(ch); } }
2.java.lang.*不明白
3.明天继续写例题