JAVA

Math 기본 실습

zammanza 2013. 2. 4. 10:13

//java.lang -> Math실습

 

public class MathEx01 {

 

        public static void main(String[] args) {

               System.out.println(Math.floor(3.2)); //floor : 내림

               System.out.println(Math.floor(3.5));

               System.out.println(Math.floor(3.7));

 

               System.out.println(Math.ceil(3.2));   //ceil : 올림

               System.out.println(Math.ceil(3.5));

               System.out.println(Math.ceil(3.7));

              

               System.out.println(Math.round(3.2)); //round : 반올림

               System.out.println(Math.round(3.5));

               System.out.println(Math.round(3.7));

       

        }

 

}

 

 

 

 

출력물


3.0
3.0
3.0
4.0
4.0
4.0
3
4
4


 

 

 

 

 

//java.lang -> Math실습(Random)

 

public class MathEx02 {

 

 

        public static void main(String[] args) {

               for(int i = 0 ; i <5 ; i++ ){

//             System.out.println(Math.random());

                      

               System.out.println((int)(Math.random() * 10));  //0~10까지 정수의 랜덤값

                                                                                                          //Math.random() * 10 먼저 계산할수 있도록 ()

              

               System.out.println((int)(Math.random()*45 + 1)); //로또 구하기

              

               }

        }

 

}

 

 

 

 

출력물


*난수발생