2016-07-24
1,math Class Introduction
Math.random () [0,1)
2, guess the number game
Homework: Guess the number of small program optimization, increase the number of times limit function.
Package com.java1995; Public class Testmath { publicstaticvoid main (string[] args) { Double d = Math.ceil (2.98); System.out.println (d); = Math.floor (2.98); System.out.println (d); System.out.println (Math.max (6.5, 4.6)); for (int i = 0; i < ten; i++) { System.out.println (Math.random ()) }}}
Packagecom.java1995;ImportJava.util.Scanner; Public classGuessnumber { Public Static voidMain (string[] args) {intnum = (int) (Math.random () * 100) + 1;//[1,100]System.out.println ("Please enter an integer between 1-100"); Scanner SC=NewScanner (system.in); while(true) { intinput =Sc.nextint (); if(Input >num) {System.out.println ("Too big."); } Else if(Input <num) {System.out.println ("Very small."); } Else{System.out.println ("Congratulations, you guessed it!" "); Break; } } //sc.close (); }}
Resources
[1] Java Easy Start Classic tutorial "full version"
Javase Advanced No. 03 Math class and guess number game