免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
Java語言程序設(shè)計基礎(chǔ)篇第三章編程練習題

3.1給出ax^2+bx+c的a.b.c系數(shù),求根;

  1. import java.util.Scanner;  
  2. public class C03t1 {  
  3.     public static void main(String[] args){  
  4.         Scanner input=new Scanner(System.in);  
  5.         System.out.println("請輸入一元二次方程a,b,c系數(shù)的值\n請輸入a:");  
  6.           
  7.         int a=input.nextInt();  
  8.         System.out.println("請輸入b:");  
  9.         int b=input.nextInt();  
  10.         System.out.println("請輸入c:");  
  11.         int c=input.nextInt();  
  12.         int x=b*b-4*a*c;  
  13.         double y1,y2;  
  14.         if(x<0)  
  15.             System.out.println("方程無解");  
  16.         else if(x==0){  
  17.             y1=(double)(-b)/(2*a);  
  18.             System.out.println("有一個根為:"+y1);  
  19.         }  
  20.         else{  
  21.             y1=((double)(-b)+Math.pow(x,0.5))/2*a;  
  22.             y2=((double)(-b)-Math.pow(x,0.5))/2*a;  
  23.             System.out.println("有兩個根為:"+y1+"和"+y2);  
  24.         }  
  25.     }  
  26.   
  27. }  


3.8輸入三個數(shù),按大小顯示

  1. import javax.swing.JOptionPane;  
  2. public class C03t8 {  
  3.     public static void main(String[] args){  
  4.         int num1,num2,num3,temp;  
  5.         String s1=JOptionPane.showInputDialog("請輸入第1個整數(shù)");  
  6.         num1=Integer.parseInt(s1);  
  7.         s1=JOptionPane.showInputDialog("請輸入第2個整數(shù)");  
  8.         num2=Integer.parseInt(s1);  
  9.         s1=JOptionPane.showInputDialog("請輸入第3個整數(shù)");  
  10.         num3=Integer.parseInt(s1);  
  11.         if(num1<num2){  
  12.             temp=num2;  
  13.             num2=num1;  
  14.             num1=temp;  
  15.         }  
  16.         if(num1<num3){  
  17.             temp=num3;  
  18.             num3=num1;  
  19.             num1=temp;  
  20.         }  
  21.         if(num3>num2){  
  22.             temp=num3;  
  23.             num3=num2;  
  24.             num2=temp;  
  25.         }  
  26.         JOptionPane.showMessageDialog(null,"MAX Number is "+num1+  
  27.                 "; the second number is "+num2+";least number is "+num3);         
  28.     }  
  29.   
  30. }  


3.14猜硬幣正反面擴展,1表示正面,0表示反面;可多次猜測,最終顯示猜測的準確率。

  1. import javax.swing.JOptionPane;  
  2. public class C03t14 {  
  3.     public static void main(String[] args){  
  4.         int count=0;                //統(tǒng)計次數(shù)  
  5.         int correctCount=0;       //統(tǒng)計正確次數(shù)  
  6.         String s1="正面請選擇是,反面請選擇否";  
  7.         String sz="本次投擲為正面,   ";  
  8.         String sf="本次投擲為反面,   ";  
  9.         String g1="恭喜你,猜對了";  
  10.         String g2="很遺憾,猜錯了";  
  11.         String sx,gx;  
  12.         while(JOptionPane.showConfirmDialog(null,"接著猜么?")==0){  
  13.         int coin=(int)(Math.random()*10)%2;  
  14.         int answer=JOptionPane.showConfirmDialog(null,s1);  
  15.         if(coin==1)  
  16.             sx=sz;  
  17.         else  
  18.             sx=sf;  
  19.         if((coin==1&&answer==0)||(coin==0&&answer==1)){  
  20.             gx=g1;  
  21.             correctCount++;  
  22.         }  
  23.         else   
  24.             gx=g2;  
  25.         JOptionPane.showMessageDialog(null,sx+gx);  
  26.         count++;  
  27.         }  
  28.         double x=(double)correctCount/count*100;  
  29.         JOptionPane.showMessageDialog(null,"你猜測準確率為"+x+"%.");  
  30.           
  31.     }  
  32.   
  33. }  


 

本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊舉報。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
java的四種輸入方法,你會幾種?
文件夾操作及zip的子文件讀取,解壓-文件下載
JAVA中indexOf函數(shù)用法
java web 處理大量用戶并發(fā)提交的簡單思路:隊列加定時提交
java輸出顏色代碼
Java讀取PDF文字內(nèi)容的方法
更多類似文章 >>
生活服務(wù)
分享 收藏 導長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服