数组河北工业大学java程序设计实验报告

java抽奖程序  时间:2021-04-26  阅读:()

精品--

Java程序设计

实验报告

班级 网络151姓名 徐毅民

学号: 153299

----精品

精品--

实验一 J ava语言基础

一实验目的

掌握J av a语言的基本语法、基本数据类型的使用方法掌握从键盘输入基本类型的数据熟练运用分支、循环等语句控制程序流程。

二实验内容

1、编写一个Java应用程序用户从键盘输入十名学生的信息至少包括姓名、年龄、出生年月日、 j ava课程实验成绩成绩使用浮点数年龄使用整型程序将输出年龄、 j ava课程实验成绩的平均值。

提示 Scanner对象调用nextDouble()或nextFloat()可以获取用户从键盘输入的浮点数。

2、使用Array s类实现数组排序使用j ava.util包中的Array s类的类方法public static void sort(double a[])可以把参数a指定的double类型数组按升序排序 public static void sort(double a[], int start , int end)可以把参数a指定的double类型数组中从位臵start到end位臵的值按升序排序。

给定数组int a[]={12,34,9,-23,45,6,90,123,19,45,34};从键盘读入一个整数使用折半查找判断该整数是否在这个数组中并将结果输出。

3、输出100~200之间的所有素数。

4、采用for循环求1至1000之内的所有“完全数”。所谓“完全数”是指一个数恰好等于它的因子之和。例如 6是一个完全数因为6的因子为1、 2、 3而61+2+3。

----精品

精品--

5、 已知XYZ+YZ Z=532其中X、 Y和Z为数字编程求出X Y和Z的值。

三实验步骤

实验1以最终学生信息管理系统为准

实验2代码如下imp ort j ava.util.Arrays;import java.util.Scanner;public class test2 {public static void printDoubleArray(double a[]) {fo r(int i=0; i<a.length; i++) {

Sys tem.o ut.p rint(a[i]+" ");

}

Sys t em.o ut.p rintln();

}public static void printfIntegerArray(int a[]) {fo r(int i=0; i<a.length; i++) {

Sys tem.o ut.p rint(a[i]+" ");

}

Sys t em.o ut.p rintln();

}public static void main(String[]args) {

----精品

精品--double a[]={2.6,4.6,2,8,888,569.5,454.5, 100, -84.5,45};Sys tem.o ut.p rintln("原do uble数组a:");p rin tD o ubleArray(a);

Arrays.s o rt(a,0,a.length/2);

Sys tem.o ut.p rintln("排序do uble数组a前一半:");p rin tD o ubleArray(a);

Arrays.s o rt(a);

Sys tem.o ut.p rintln("排序整个do uble数组a:");p rin tD o ubleArray(a);int b[]={12,34,9, -23,45,6,90, 123, 19,45,34};

Arrays.s o rt(b);

Sys tem.o ut.p rintln("排序整个do uble数组b:");p rin tfIn te gerArray(b);

Scanner in=new Scanner(System.in);

Sys tem.o ut.p rint("输入要查询的数字:");int key=in.nextInt();int i=Arrays.binarySearch(b,key);if(i<0 | | i>=b.length) {

Sys tem.o ut.p rintln(i+"输入数字不在数组中!");} else {

Sys tem.o ut.p rintln(b[i]+"在数组b第"+(i+1)+"位 ");

----精品

精品--

}

}

}

实验3代码如下public class test3 {public static boolean isPrime(int x) {if(x==1) return false;in t s=(int)M ath.s qrt(x);for(int i=2; i<=s; i++) {if(x%i==0) return false;

}return true;

}public static void main(String[]args) {int cnt=0;for(int i=100; i<200; i++) {if(isPrime(i)) {cnt++;

Sys tem.o ut.p rintf("%4d", i);

}if(is P rim e(i)&&cn t%10==0) Sys tem.o ut.p rintln();----精品

精品--

}

}

}

实验4代码如下public class test4{public static boolean isCompleteNumber(int x) {int sum=0;for(int i=1; i<x; i++) {if(x%i==0) sum+=x;

}return x==sum;

}public static void main(String[]args) {int cnt=0;for(int i=1; i<=1000; i++) {if(isCompleteNumber(i)) {cnt++;

Sys tem.o ut.p rintf("%4d", i);

}if(isCompleteNumber(i)&&cnt%10==0)Sy s t em.o ut.p rintln();

----精品

精品--

}

}

}

实验5代码如下public class test5 {public static void main(String[]args) {for(int x=0;x<10;x++) {for(int y=0;y<10;y++) {for(int z=0;z<10;z++) {if(100*x+110*y+12*z==532) {

Sy s t em.o ut.p rintln("X="+x+"Y="+y+"Z="+z);return;

}

}

}

}

}

}

四详细的调试和运行结果

实验2运行结果

----精品

精品--

原do uble数组a

2.6 4.6 2.0 8.0 888.0 569.5 454.5 100.0 -84.5 45.0排序do uble数组a前一半

2.0 2.6 4.6 8.0 888.0 569.5 454.5 100.0 -84.5 45.0排序整个double数组a

-84.5 2.0 2.6 4.6 8.0 45.0 100.0 454.5 569.5 888.0排序整个double数组b

-23 6 9 12 19 34 34 45 45 90 123

输入要查询的数字 -23

-23在数组b第一位

实验3运行结果

101 103 107 109 113 127 131 137 139 149

151 157 163 167 173 179 181 191 193 197

199

实验4运行结果

2 3 5 7 11 13 17 19 23 29

----精品

精品--

31 37 41 43 47 53 59 61 67 71

73 79 83 89 97 101 103 107 109 113

127 131 137 139 149 151 157 163 167 173

179 181 191 193 197 199 211 223 227 229

233 239 241 251 257 263 269 271 277 281

283 293 307 311 313 317 331 337 347 349

353 359 367 373 379 383 389 397 401 409

419 421 431 433 439 443 449 457 461 463

467 479 487 491 499 503 509 521 523 541

547 557 563 569 571 577 587 593 599 601

607 613 617 619 631 641 643 647 653 659

661 673 677 683 691 701 709 719 727 733

739 743 751 757 761 769 773 787 797 809

811 821 823 827 829 839 853 857 859 863

877 881 883 887 907 911 919 929 937 941

947 953 967 971 977 983 991 997

实验5运行结果

X=3 Y=2 Z=1

五实验感想

通过本次从实验对j ava语言的基本语法有了基本了解学会了使----精品

SunthyCloud阿里云国际版分销商注册教程,即可PayPal信用卡分销商服务器

阿里云国际版注册认证教程-免绑卡-免实名买服务器安全、便宜、可靠、良心,支持人民币充值,提供代理折扣简介SunthyCloud成立于2015年,是阿里云国际版正规战略级渠道商,也是阿里云国际版最大的分销商,专业为全球企业客户提供阿里云国际版开户注册、认证、充值等服务,通过SunthyCloud开通阿里云国际版只需要一个邮箱,不需要PayPal信用卡就可以帮你开通、充值、新购、续费阿里云国际版,服务...

昔日数据月付12元起,湖北十堰机房10M带宽月付19元起

昔日数据怎么样?昔日数据是一个来自国内服务器销售商,成立于2020年底,主要销售国内海外云服务器,目前有国内湖北十堰云服务器和香港hkbn云服务器 采用KVM虚拟化技术构架,湖北十堰机房10M带宽月付19元起;香港HKBN,月付12元起; 此次夏日活动全部首月5折促销,有需要的可以关注一下。点击进入:昔日数据官方网站地址昔日数据优惠码:优惠码: XR2021 全场通用(活动持续半个月 2021/7...

华纳云-618大促3折起,18元/月买CN2 GIA 2M 香港云,物理机高防同享,10M带宽独享三网直连,无限流量!

官方网站:点击访问华纳云活动官网活动方案:一、香港云服务器此次推出八种配置的香港云服务器,满足不同行业不同业务规模的客户需求,同时每种配置的云服务都有不同的带宽选择,灵活性更高,可用性更强,性价比更优质。配置带宽月付6折季付5.5折半年付5折年付4.5折2年付4折3年付3折购买1H1G2M/99180324576648直达购买5M/17331556710081134直达购买2H2G2M892444...

java抽奖程序为你推荐
盗版itunes输入ipad奶粉ios8iphone连不上wifi苹果手机为什么突然连不上家里的wifi?重庆电信网速测试如何测量网速win7还原系统电脑怎么恢复出厂设置win7旗舰版联通合约机iphone5联通合约机iphone5和电信合约机Iphone5哪个好google统计google分析里的数据包括搜索引擎爬虫的数据吗?Google中文专题交流bitchina现在哪个浏览器最好用?卡巴斯基好用吗卡巴斯基好吗
域名注册com 域名服务器的作用 香港ufo winhost webhostingpad 好看的留言 国外网站代理服务器 合租空间 天翼云盘 常州联通宽带 申请免费空间和域名 中国电信测速器 帽子云排名 工信部网站备案查询 工信部icp备案查询 hdchina 学生机 windowssever2008 美国代理服务器 cpu使用率过高怎么办 更多