




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、/* 大家好,我现在正在学习java,虽然在这之前我已经学习过一遍了,但是现在再重新来学,才发现以前学的太肤浅了,而且学的质量也很不好,所以,现在我又重新站在了新的起跑线上,开始了我的java学习之旅,喜欢java的朋友和想学习java的朋友来和我一起前进吧。我会及时的把自己学的一些东西总结出来,并传送到文库中和大家一起分享的。 所以Make The Change的时候到了,Everyone,Come On!(我的QQ号,愿意交流的同学可以加我呦)*/*1 螺旋方阵:例:12345161718196152071422218131211109代码实现如下:*
2、/import java.util.Scanner;public class SpiralSquare public static void main(String args) Scanner s=new Scanner(System.in);System.out.println(请输入螺旋方阵的边长);int index=s.nextInt();if(index=0)System.out.println(输入的数字不合法!);return;int square=new intindexindex;int col=-1;/define columnint row=0;/define rowfo
3、r(int i=1;i=index*index;)while(col+1index&squarerowcol+1=0) squarerow+col=i+;while(row+1=0&squarerowcol-1=0)squarerow-col=i+;while(row-1=0&squarerow-1col=0) square-rowcol=i+;for(int i=0;isquare.length;i+)for(int j=0;jsquarei.length;j+)System.out.print(squareij+t);System.out.println();/*2 螺旋矩阵:例:1234
4、514151617613201918712111098代码实现如下:*/import java.util.Scanner;public class SpiralSquare01public static void main(String args) Scanner s=new Scanner(System.in);System.out.println(请输入螺旋方阵的长);int indexY=s.nextInt();System.out.println(请输入螺旋方阵的宽);int indexX=s.nextInt();if(indexX=0|indexY=0)System.out.prin
5、tln(输入的数字不合法!);return;int square=new intindexXindexY;int x=0;int y=0;for(int i=1;i=indexX*indexY;)while(ysquarex.length-1&squarexy+1=0)squarexy+=i+;while(x0&squarex-1y-1=0)squarex-1-y=i+;-x;while(x1&squarex-1y=0)square-xy=i+;y+;for(int i=0;isquare.length;i+)for(int j=0;jsquarei.length;j+)System.out.
6、print(squareij+t);System.out.println();/*3、模拟酒店房间管理系统,需要如下几个功能:1、1 in 房间号 客人名字 入住功能1、2 out 房间号 退房功能1、3 search 房间号 查询房间状态 如果房间号为-1 则输出所有房间状态1、4 quit 或 exit 退出提示:酒店所有的房间用二维数组来实现代码实现如下:*/import java.util.Scanner;public class HotelDemo /写在类里面,则每个方法都可以访问到,避免了参数传递的繁琐;static int h=5,w=10;static String room
7、s=new String510;public static void main(String args) Scanner s=new Scanner(System.in);while(true)System.out.println(请输入 in,out,search,quit:);String temp=s.next();int room=0;if(in.equals(temp)/防止出现空指针异常;System.out.println(输入房间号:);room=s.nextInt();System.out.println(输入名字:);String name=s.next();if(in(r
8、oom,name) System.out.println(入住完成!);System.out.println(room+room+name+name);else if(out.equals(temp)System.out.println(输入房间号:);room=s.nextInt();if(out(room) System.out.println(退房完成!);System.out.println(out+room);else if(search.equals(temp)System.out.println(输入房间号(-1代表全部):);room=s.nextInt();search(ro
9、om);else if(quit.equals(temp)|exit.equals(temp)break;elseSystem.out.println(命令错误!);private static boolean search(int room) if(room=-1)/打印所有的信息;for(int i=0;ih;i+)for(int j=0;jw;j+)int room2=(i+1)*100+j+1;System.out.print(room2+t);System.out.println();for(int k=0;kw;k+)System.out.print(roomsik=null?em
10、pty:roomsik);System.out.print(t);System.out.println();System.out.println();return true;elseint r=room/100-1;int c=room%100-1;if(r=h|c=w)System.out.println(房间号错误!);return false;System.out.println(roomsrc=null?empty:roomsrc);return true;private static boolean out(int room) int r=room/100-1;int c=room%100-1;if(r=h|c=w)System.out.println(房间号错误!);return false;if(roomsrc=null|.equals(roomsrc)/System.out.println(此房间没有人!);return false;roomsrc=null;return true;private static boolean in(int room, String name) in
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 乡村旅游项目开发2025年社会稳定风险评估与风险防控机制报告
- 暖通空调设备缺陷责任期维护方案及保证措施
- 高校课程思政教学质量提升心得体会
- 五年级上语文教学反馈机制措施
- 给集团高层领导的一封公开信范文
- 幼儿园保育流程培训工作计划
- 小班动物观察与记录主题计划
- 2025年六年级班主任班级氛围营造计划
- 机械设备、办公设备及检测设备环保改进计划
- 2025年护理部护理服务信息共享推广计划
- 云南省文山州州属事业单位选调工作人员笔试真题2024
- 2025年深圳市的房屋租赁合同
- 新疆平台经济发展调研报告2025
- 企业安全声明
- 检验科职业暴露培训课件
- 教师职业素养课件教学
- 汽车网销电话邀约话术培训
- 煤矿掘进试题库及答案
- 地坪材料推广活动方案
- 音乐数据分析与用户行为研究-洞察阐释
- 2025至2030中国电子级磷酸行业市场发展分析及市场需求与投资方向报告
评论
0/150
提交评论