Java趣味程序(二)_第1页
Java趣味程序(二)_第2页
Java趣味程序(二)_第3页
Java趣味程序(二)_第4页
Java趣味程序(二)_第5页
已阅读5页,还剩6页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论