用java提示用户输入学生个数_次Java练习题.doc

次Java练习题

顺序语句练习

6道题.方法1道.数组2道。类2到

建项目Test+学号

每个题一个包

把每个项目压缩 专业班级学号姓名 提交

时间 3小时

数组: 做题号为偶数的 去掉柜子 八皇后

方法 :1 3 11 13 14 16

类: 1 5 4 6 7 8 9 14 15 16

异常:

.循环练习

public class lx5 {

public static void main(String args[]){

System.out.println("50以内的素数:");

System.out.print("2 "+"3 ");

int c=2;

for(int i=3;i<=100;i++)

for(int j=2;j<=(int)Math.sqrt(i);j++){

if(i%j==0)break;

if(j>=(int)Math.sqrt(i)){

System.out.print(i+" ");

c++;

if(c%10==0)

System.out.println();

}

}

}

}

6.(统计正数和负数的个数然后计算这些数的平均值)编写程序,读入未指定个数的整数,分别判断读入的正数和负数的个数,然后计算这些输入值的总和及其平均值(不对0计数),当输入为0时候,表示程序结束。将平均值以浮点数的形式显示。(20分)

下面是一个运行示例:

Enter an int value, the program exits if the input is 0:

1 2 -1 3 0

The number of positives is 3

The number of negatives is 1

The total is 5

The average is 1.25

7.(财务程序) :假设某个大学今年的学费是10000元,学费以每年5%速度增加,编写程序计算10年后的学费以及现在开始的10年后算起,4年内总学费是多少?(20分)

public static void main(String[] args) {

int a=10000;

double w;

double sum=0;

double p;

for(int n=1;n<10;n++){

w=a*Math.pow(1+0.05,n);

sum+=w;

if(n==9){

System.out.println(" "+w);

}

if(n==3){

p=a+sum;

System.out.println(" "+p);

}

}

}

}

8.编写程序,提示用户输入学生的个数,每个学生的姓名和分数,最后显示得分最高学生的姓名和分数和第二高分学生姓名和分数(20分)

import java.io.*; import java.util.*;public class lianxi50 { public static void main(String[] args){ ?? Scanner ss = new Scanner(System.in);?? String [][] a = new String[5][6];?? for(int i=1; i<6; i++) {??? System.out.print("请输入第"+i+"个学生的学号:");??? a[i-1][0] = ss.nextLine();??? System.out.print("请输入第"+i+"个学生的姓名:");??? a[i-1][1] = ss.nextLine();??? for(int j=1; j<4; j++) {?????? System.out.print("请输入该学生的第"+j+"个成绩:");?????? a[i-1][j+1] = ss.nextLine();?????? }System.out.println("\n");public static void main(String[] args) {

int n=1;

while(n*n <12000){

n++;

}

System.out.println(" "+n);

}

}

11. 计算π(25分)

使用下列数列可以近似计算π:

π= 4*(1-1/3 +1/5 -1/7 + 1/9 -1/11+………+1/(2*i-1)-1/2*i+1)

编写程序,显示当i

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值