第一范文网 - 专业文章范例文档资料分享平台

Java 输入输出流及文件读写详解

来源:用户分享 时间:2025/6/2 20:35:59 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

}

}

// 掷骰子

diceNum = doDice(); // 判断胜负

success = isSuccess(type,diceNum); // 金钱变化

money = changeMoney(money,success,cMoney); // 游戏结束 if(isEnd(money)){ }

System.out.println(\你输了,bye!\ break;

/**

* 读取用户输入

* @return 玩家输入的整数,如果格式非法则返回0 */

public static int readKeyboard() { } /**

* 押的类型校验

try {

// 缓冲区数组

byte[] b = new byte[1024]; // 读取用户输入到数组b中, // 读取的字节数量为n int n = System.in.read(b); // 转换为整数

String s = new String(b, 0, n - 2); int num = Integer.parseInt(s); return num;

} catch (Exception e) {} return 0;

* @param type 类型

* @return true代表符合要求,false代表不符合 */

public static boolean checkType(int type) { } /**

* 校验下注金额是否合法 * @param money 玩家金钱数 * @param cMoney 下注金额

* @return true代表符合要求,false代表不符合要求 */

public static boolean checkCMoney(int money, int cMoney) { } /** * 掷骰子

* @return 骰子的数值之和 */

public static int doDice() {

int n = (int) (Math.random() * 6) + 1; int n1 = (int) (Math.random() * 6) + 1; int n2 = (int) (Math.random() * 6) + 1; if (cMoney <= 0) { }

return false; return true; return false;

} else if (cMoney <= money) { } else {

if (type == 1 || type == 2) { }

return true; return false; } else {

}

// 输出随机结果

System.out.println(\庄家开:\ return n + n1 + n2;

/**

* 胜负判断

* @param type 用户输入类型 * @param diceNum 骰子点数 * @return true代表赢,false代表输 */

public static boolean isSuccess(int type, int diceNum) { } /**

* 金钱变化

* @param money 用户钱数 * @param success 胜负 * @param cMoney 下注金额 * @return 变化以后的金钱 */

// 计算庄家类型 int bankerType = 0; if (diceNum <= 9) { }

if (bankerType == type) { // 赢 }

return true; return false; } else { // 输

bankerType = 2;

System.out.println(\庄家开小!\ bankerType = 1;

System.out.println(\庄家开大!\

} else {

{ }

public static int changeMoney(int money, boolean success, int cMoney) } /**

* 判断游戏是否结束 * @param money 玩家金钱 * @return true代表结束 */

public static boolean isEnd(int money) { }

return money <= 0; if (success) { }

System.out.println(\剩余金额:\ return money;

money += cMoney; money -= cMoney; } else {

注意问题

上面介绍了IO类的基本使用,熟悉了实体流和装饰流的基本使用,但是在IO类实际使

用时,还是会遇到一系列的问题,下面介绍一些可能会经常遇到的问题。

类的选择

对于初次接触IO技术的初学者来说,IO类体系博大精深,类的数量比较庞大,在实际

使用时经常会无所适从,不知道该使用那些类进行编程,下面介绍一下关于IO类选择的一些技巧。

选择类的第一步是选择合适的实体流。

选择实体流时第一步是按照连接的数据源种类进行选择,例如读写文件应该使用文件流,

搜索更多关于: Java 输入输出流及文件读写详解 的文档
Java 输入输出流及文件读写详解.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c0lb721p74v507xn0vyso_7.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top