立即注册 登录
气象家园 返回首页

15195775117的个人空间 http://bbs.06climate.com/?43007 [收藏] [复制] [分享] [RSS]

日志

Java编程案例之Scanner

已有 70 次阅读2018-5-4 09:02 |个人分类:Java| Scanner

Java中的Scanner~C中的scanf,即程序运行后是需要等待键入内容的。

import java.util.Scanner;
public class JL {
 public static void main(String[] args) {
  Scanner input=new Scanner(System.in);
  double a=input.nextDouble();
  double b=input.nextDouble();

  double a2 = fg.f(3);
  double b2 = fg.g(5);
  System.out.print(a2 + b2);
 }

//方法fg()
 public static class fg {
  static int f(int x) {
   return (x * 10);
  }

  static int g(int y) {
   return (y * 100);
  }
 }
}

控制台输出5,回车,输入3,回车,输出:

530.0

发表评论 评论 (1 个评论)

回复 15195775117 2018-5-4 09:07
Scanner类后的方法有nextByte   nextInt()   nextLong() nextShort() nextFloat() nextDouble() nextLine(),可见严格限定了输入数据的类型!Java果然是强类型语言!

facelist doodle 涂鸦板

您需要登录后才可以评论 登录 | 立即注册

Copyright ©2011-2014 bbs.06climate.com All Rights Reserved.  Powered by Discuz! (京ICP-10201084)

本站信息均由会员发表,不代表气象家园立场,禁止在本站发表与国家法律相抵触言论

返回顶部