简单的文本扫描器,能够使用正则表达式解析原始类型和字符串,能够经过该类获取用户输入java
Scanner直接继承于Object,位于java.util下,也就意味着使用前须要导包正则表达式
import java.util.Scannersql
Scanner(File source); //使用文件构造扫描器 Scanner(InputStream source) //使用输入流构造扫描器 Scanner(Path source) //使用指定路径文件构造扫描器
void close() //关闭扫描器 boolean hasNextXxx() //Xxxk能够是Double,Byte,Int等 //判断下一个输入项是不是Xxx boolean hasNext() //判断是否有下一个输入项 String nextLine() //获取下一行字符串,包含回车 Xxx nextXxx() //获取下一个输入,不包含回车
import java.util.Scanner; //导入Scanner public class Demo { public static void main(String args[]){ Scanner sc=new Scanner(System.in); //经过标准输入流构造Scanner System.out.println("Please input an integer!"); if(sc.hasNextInt())//若是若是是Int数打印该数字 System.out.println("The number is "+sc.nextInt()); else//若是不是打印错误信息 System.out.println("Input error!"); } }
java.lang.Mathdom
Math 类包含用于执行基本数学运算的方法,如初等指数、对数、平方根和三角函数。函数
public static int abs(int a) //求绝对值 public static double ceil(double a) //向上取整 public static double floor(double a) //向下取整 public static int max(int a,int b) //返回两者较大值 public static double pow(double a,double b) //返回a的b次方 public static double random() //生成0~1之间的随机小数 public static int round(float a) //四舍五入为整数 public static double sqrt(double a) //开方运算
java.util.Randomcode
用于产生随机数,能够设置种子对象
public Random()//以当前时间为种子 public Random(long seed)//指定种子
public int nextInt()//返回一个int数 public int nextDouble()//返回一个Double数 public int nextInt(int n)//返回一个数t,0<=t<n
java.lang.System继承
System 类包含一些有用的类字段和方法。它不能被实例化。字符串
static PrintStream err //“标准”错误输出流。 static InputStream in //“标准”输入流。 static PrintStream out //“标准”输出流。
public static void gc()//运行垃圾回收器 public static void exit(int status)//终止当前虚拟机,非0为异常终止 public static long currentTimeMillis()//获取系统当前时间
java.sql.Dateget
一个时间相关的类,类 Date 表示特定的瞬间,精确到毫秒。
public Date()//建立当前时间对象 public Date(long date)//指定毫秒建立对象
public long getTime()//获取时间(毫秒) public void setTime(long time)//设置时间(毫秒)