ImageVerifierCode 换一换
格式:DOCX , 页数:12 ,大小:17.26KB ,
资源ID:2185507      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bingdoc.com/d-2185507.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(《Java程序设计》作业一.docx)为本站会员(b****1)主动上传,冰点文库仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰点文库(发送邮件至service@bingdoc.com或直接QQ联系客服),我们立即给予删除!

《Java程序设计》作业一.docx

1、Java程序设计作业一Java程序设计作业一一、 5.1(1) 题目:(统计正数和负数的个数然后计算这些数的平均值)编写程序,读入未指定个数的整数,判断读入的正数有多少个,读入的负数有多少个,然后计算这些输入值的总和及其平均值(不对0计数)。当输入为0时,表明程序结束。将平均值以浮点数显示。(2) 代码import java.util.Scanner;public class home1 public static void main(String args) int number,count1=0,count2=0,total=0; double a=0; System.out.printl

2、n(Enter an integer,the input ends if it is 0:);Scanner input = new Scanner (System.in); do number=input.nextInt(); if(number0) count1+; if(number100&i1000;i+) if(i%5=0&i%6=0) count+; System.out.printl(i+); if(count%10=0) System.out.println(n); (3) 运行结果The number is:120 150 180 210 240 270 300 330 36

3、0 390 420 450 480 510 540 570 600 630 660 690 720 750 780 810 840 870 900 930 960 990三、 5_40(1) 题目:(模拟:正面或反面)编写程序,模拟硬抛币一百万次,显示出现正面和反面的次数(2) 解题思路 输入/输出设计: 输入内容:随机产生0和1两个数 输出内容:正面次数,反面次数 变量/常量设计: int count=(int)(Math.random() * 2);/随机产生0,1两位数 int i;/控制抛币次数int positive=0;/正面次数int negative=0;/反面次数 数据处理步

4、骤设计和方法设计:程序处理步骤如下:第一步:初始化i,positive,negative的值;第二步: 控制抛币次数,进入循环;第三步:随机产生0,1两个数赋给count;第四步:如果count=0,negative+,如果count=1,positive+第五步:输出positive negative 测试设计1分:产生随机数0和1(3) 代码public class home3 public static void main(String args) int i,positive=0,negative=0; System.out.println(The negative is:); Sys

5、tem.out.println(The positive is:); for(i=1;i=ch1&i=ch2;i+) System.out.print(char)i+ ); count+; if(count%10=0) System.out.println(n); (3) 运行结果The number is:1 2 3 4 5 6 7 8 9 : ; ? A B C D E F G H I J K L M N O P Q R S T U V W X Y Z六、 7_4(1) 题目:(分析成绩)编写一个程序,读入个数不确定的考试分数,并且判断有多少个分数是大于或等于平均分,多少个分数是低于平均分

6、的,输入一个负数表示输入结束,假设最高分为100(2) 代码import java.util.Scanner;public class home6 public static void main(String args)int number,count1=0,count2=0,total=0; double a=0;System.out.println(Enter your score:); Scanner input = new Scanner (System.in); do number=input.nextInt(); if(number=a) count1+; if(numbera)

7、count2+; /if(number=0&number=aversge +count1); System.out.println(The number =aversge2The number average1The average is:59.0七、 7_8(1) 题目:编写两个重载的方法,使用下面两个方法头,返回一个数组的平均数(2) 代码public static int average(int array)public static double average(double array)public class home7 public static void main(String

8、 args) int a=new int10; double d=new double10; Scanner input = new Scanner (System.in); System.out.println(Please intput ten double number); for( int x=0;xd.length;x+) dx=input.nextDouble(); System.out.println(The doubler average is:+average(d);public static double average(double array)double d_tota

9、l=0;double d_aver=0;for(int x=0;xarray.length;x+)d_total=d_total+arrayx;d_aver=d_total/array.length; return d_aver;public static int average(int array) int total=0,aver=0;for(int i=0;iarray.length;i+)total=total+arrayi;aver=total/array.length;return aver;(3) 运行结果Please intput ten double number1.2 3.

10、4 3.4 6.7 3.5 4.0 3 5 6 7The doubler average is:4.32八、 7_9(1) 题目:(找出最小数)编写一个方法,使用下面的方法头求出一个整数数组中的最小元素public static double min(double array)编写测试程序,提示用户输入十个数字,调用这个方法返回最小值,显示其最小值(2) 代码import java.util.Scanner;public class home8 public static void main(String args) double d=new double10; Scanner input =

11、 new Scanner (System.in); System.out.println(Please intput ten number); for( int x=0;xd.length;x+) dx=input.nextDouble(); System.out.println(The min number is:+min(d); public static double min(double array) double a=array0; for(int i=0;iarray.length;i+) if(arrayia) a=arrayi; return a; (3) 运行结果:(4) Please intput ten number7.0 6.0 7.6 4 5 6 7 3 2 6The min number is:2.0

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2