一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

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

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

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 91成人爽a毛片一区二区 | 欧美日韩国产精品自在自线 | 国产麻豆精品免费视频 | 果冻传媒mv在线观看入口免费 | 日本色吧 | 车上小婕子系列辣文小说 | 丰满岳乱妇在线观看视频国产 | 亚洲 欧美 中文字幕 在线 | 亚洲成人综合在线 | 高清欧美不卡一区二区三区 | 97自拍视频在线观看 | 91天堂一区二区 | 国产精品四虎在线观看免费 | 温柔校草高h | 日产精品一卡2卡三卡4乱码久久 | 91天堂在线视频 | 高考录取率1977-2021 | 青青草亚洲 | 风间由美被义子中文字幕 | 国产成人综合精品一区 | 亚洲 欧美 国产 在线 日韩 | 香蕉久久网 | 强女明星系列小说 | 天天干天天爽天天操 | 日韩在线毛片 | 日本一区二区在线不卡 | 欧美va天堂va视频va在线 | 男人的天堂久久精品激情a 男人的天堂va | 亚洲国产精品久久无套麻豆 | 污黄漫| 成年人在线观看免费视频 | 亚洲欧美日韩中文字幕网址 | 99热这里只有精品免费 | 99re8在线精品视频免费播放 | 久久精品一区二区三区资源网 | 亚洲九九九 | 91色爱| 亚洲AV 中文字幕 国产 欧美 | 91精品久久| 欧美2区 | 贰佰麻豆剧果冻传媒一二三区 |