1. 程式人生 > 實用技巧 >2020.8.11第三十六天

2020.8.11第三十六天

例3.1求一元二次方程的根

 1 import java.util.Scanner;
 2 public class cjava {
 3     public static void main(String[] args) {
 4         float a,b,c,x1,x2;
 5         Scanner s=new Scanner(System.in);
 6         System.out.println("輸入a,b,c的值:");
 7         a=s.nextInt();
 8         b=s.nextInt();
 9         c=s.nextInt();
10 x1=(float)((-b+Math.sqrt(b*b-4*a*c))/(2*a)); 11 x2=(float)((-b-Math.sqrt(b*b-4*a*c))/(2*a)); 12 System.out.println("x1="+x1); 13 System.out.println("x2="+x2); 14 } 15 }

例3.2求三角形面積

 1 import java.util.Scanner;
 2 import java.lang.*;
 3 public class cjava {
 4     public
static void main(String[] args) { 5 float a,b,c,x1,x2; 6 double s,area; 7 Scanner g=new Scanner(System.in); 8 System.out.println("輸入a,b,c的值:"); 9 a=g.nextInt(); 10 b=g.nextInt(); 11 c=g.nextInt(); 12 if(a+b>c&&b+c>a&&a+c>b)
13 { 14 s=(a+b+c)/2; 15 area=Math.sqrt(s*(s-a)*(s-b)*(s-c)); 16 System.out.println("area="+area); 17 } 18 else 19 System.out.println("it is not a trilateral!"); 20 } 21 }

例3.3判斷字元大小寫,大寫轉換為小寫,小寫不轉換

 1 import java.util.Scanner;
 2 public class cjava {
 3     public static void main(String[] args) {
 4         char ch;
 5         Scanner g=new Scanner(System.in);
 6         System.out.println("輸入ch:");
 7         String s;
 8         s=g.next();
 9         ch=s.charAt(0);
10         if(ch>='A'&&ch<='Z')
11         {
12         ch+=32;
13         System.out.println(ch);
14         }
15         else
16             System.out.println(ch);
17     }
18 }

2.今天不知道怎麼用數學函式,百度查詢到java.lang

3明天繼續寫例題