激情久久久_欧美视频区_成人av免费_不卡视频一二三区_欧美精品在欧美一区二区少妇_欧美一区二区三区的

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術|正則表達式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務器之家 - 編程語言 - Java教程 - Java最常用的6個簡單的計算題

Java最常用的6個簡單的計算題

2021-04-07 13:19彬菌 Java教程

本篇文章給大家整理的在JAVA中最常用到的簡單的計算題,對此有興趣的朋友可以測試參考下。

1、3個白球 3個紅球 6個黑球 隨機拿出8個球,算出所有結果

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
public class Ball{
  public static void main(String[] args){
  int a=3,b=3,c=6,i=0;
  for (int x=0;x<=a;x++){
    for (int y=0;y<=b;y++){
        for (int z=0;z<=c;z++){
            if (x+y+z==8){
      System.out.println("紅球 " + x + "\t白球 " + y + "\t黑球 " + z );
      i++;
        }
       }
     }
   }
   System.out.println("有" + i + "結果");  
  }
}

2、數字金字塔

?
1
2
3
4
5
6
7
8
9
10
public class Pyramid {
public static void main(String args[]){
  for (int i=1; i<=32; i=i*2) {
    for (int k=1; k<=32/i; k=k*2)System.out.print("\t");
    for (int j=1; j<=i; j=j*2)System.out.print("\t"+j);
    for (int m=i/2; m>=1; m=m/2) System.out.print("\t"+m);
    System.out.print("\n");
        }
      }
   }

3、簡單的判斷日期格式是否正確

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import java.util.Scanner;
 
public class Date{
public static void main(String[] args) {
  @SuppressWarnings("resource")//取消對input的警報
  Scanner input=new Scanner(System.in);//聲明掃描儀變量
  System.out.println("請輸入----年--月--日");//系統提示輸入
  int y = input.nextInt();
  int m = input.nextInt();
  int d = input.nextInt();
  if (y>=1900&&y<=2050&&m>=1&&m<=12&&d>=1&&d<=31)
    System.out.print("日期正確");
  else
    System.out.print("日期不正確");
  }
}

4、計算1+2/3+3/5+4/7+5/9…的前20項的和

?
1
2
3
4
5
6
7
8
public class Num{
    public static void main(String[] args) {
        double sum=0;
        for(int i=1;i<=10;i++)
           sum=sum+i/(2.0*i-1);
        System.out.println(sum);
    }
}

5、給出本金,利率,年限計算存款(以函數的方式)

?
1
2
3
4
5
6
7
8
9
10
11
12
public class Bank {
  public static double CBM(double money,double interest,int years){ 
    for(int i=1;i<=years;i++){  
      money = money *(1+ interest); 
    }
    return money;
  }
  public static void main(String[] args) {
      System.out.println("300000元10年后的存款金額為"+CBM(300000,0.07,20));
      System.out.println("200000元20年后的存款金額為"+CBM(200000,0.06,20));
  }
}

6、計算五邊形的面積。輸入r,求面積s

?
1
2
3
4
5
6
7
8
9
10
11
12
13
import java.util.Scanner;
 
public class Circular{
  public static void main(String[] args) {
    @SuppressWarnings("resource")//取消對input的警報
    Scanner input=new Scanner(System.in);//聲明掃描儀變量
    System.out.println("請輸入五邊形半徑");//系統提示輸入
    double r = input.nextDouble();
    double S;
    S=5*(2*r*Math.sin(Math.PI/5)*(Math.pow(2*r*Math.sin(Math.PI/5), 2))/(4*Math.tan(Math.PI/5)));
    System.out.println("五邊形的面積為"+S);
  }
}

原文鏈接:https://www.idaobin.com/archives/375.html

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 久久网站热最新地址4 | 妇女毛片 | 免费一级毛片电影 | 久久久久久91 | 激情久久一区二区 | 亚洲精品欧美在线 | 涩涩屋av | 欧美三级日本三级少妇99 | 永久免费在线观看av | 99精品视频在线观看免费播放 | 在线看91 | 免费在线观看午夜视频 | 国产亚洲精品久久午夜玫瑰园 | 久久国产精品久久久久久 | 久久一本日日摸夜夜添 | 精品二区在线观看 | 黄色网址www | 久久久一区二区三区精品 | 欧美成人鲁丝片在线观看 | 日本一区二区在线 | 成人激情综合网 | 久久久看 | 欧美激情在线播放 | 亚洲特黄妇女高潮 | 色综合中文字幕 | 毛片大全免费看 | 国产成人精品区 | 美女黄页网站免费进入 | 久久国产精品免费视频 | 成人福利在线免费观看 | 欧美一级视屏 | 视频在线91| 中文字幕xxx | 免费嗨片首页中文字幕 | 精品国产一区二区三区蜜殿 | 精品久久一区二区三区 | 欧美一级高清片在线 | 日本综合久久 | 免费h片 | 黄色毛片前黄 | 国产毛片aaa一区二区三区视频 |