Scanner和BufferedReader从控制台读取输入数据
Scanner和BufferedReader从控制台读取输入数据
哎小艾 发表于7个月前
Scanner和BufferedReader从控制台读取输入数据
  • 发表于 7个月前
  • 阅读 5
  • 收藏 0
  • 点赞 0
  • 评论 0

新睿云服务器60天免费使用,快来体验!>>>   

1、Scanner方式

类路径:java.util.Scanner

        Scanner scanner = new Scanner(System.in);
		while(true){
			System.out.println("请输入");
			
			//调用scanner.nextLine()方法
			int fubenId = Integer.parseInt(scanner.nextLine());
			int count = Integer.parseInt(scanner.nextLine());
			
			FightRequest fightRequest = new FightRequest();
			fightRequest.setFubenId(fubenId);
			fightRequest.setCount(count);
			
			Request request = new Request();
			request.setModule((short) 1);
			request.setCmd((short) 1);
			request.setData(fightRequest.getBytes());
			
			//发送请求
			channel.write(request);
		}

2、BufferedReader方式

类路径:java.io.BufferedReader

        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
		while(true){
			System.out.println("请输入:");
			
			//调用bufferedReader.readLine()方法
			int fubenId = Integer.parseInt(bufferedReader.readLine());
			int count = Integer.parseInt(bufferedReader.readLine());
			
			FightRequest fightRequest = new FightRequest();
			fightRequest.setFubenId(fubenId);
			fightRequest.setCount(count);
			
			Request request = new Request();
			request.setModule((short) 1);
			request.setCmd((short) 1);
			request.setData(fightRequest.getBytes());
			
			channel.write(request);
		}

 

  • 打赏
  • 点赞
  • 收藏
  • 分享
共有 人打赏支持
粉丝 11
博文 166
码字总数 124687
×
哎小艾
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: