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
相关文章
猜你喜欢
- 64M VPS建站:怎样选择合适的域名和SSL证书? 2025-06-10
- 64M VPS建站:怎样优化以提高网站加载速度? 2025-06-10
- 64M VPS建站:是否适合初学者操作和管理? 2025-06-10
- ASP.NET自助建站系统中的用户注册和登录功能定制方法 2025-06-10
- ASP.NET自助建站系统的域名绑定与解析教程 2025-06-10
TA的动态
- 2025-07-10 怎样使用阿里云的安全工具进行服务器漏洞扫描和修复?
- 2025-07-10 怎样使用命令行工具优化Linux云服务器的Ping性能?
- 2025-07-10 怎样使用Xshell连接华为云服务器,实现高效远程管理?
- 2025-07-10 怎样利用云服务器D盘搭建稳定、高效的网站托管环境?
- 2025-07-10 怎样使用阿里云的安全组功能来增强服务器防火墙的安全性?
快网idc优惠网
QQ交流群
您的支持,是我们最大的动力!
热门文章
-
2025-05-27 70
-
2025-06-04 97
-
PHP常量DIRECTORY_SEPARATOR原理及用法解析
2025-05-27 87 -
2025-05-29 74
-
2025-05-25 86
热门评论