In Java with the help of Math class we can perform certain Mathematics.
Let's have a look-
System.out.println(Math.min(20,40));
>Print-20
System.out.println(Math.max(30,10);
>Print-30
System.out.println(Math.sqrt(36));
>Print-6
System.out.println(Math.abs(-16.09));
>Print-(16.09 -without negative sign)
System.out.println(Math.random());
>Print- random decimal value
How to get integer random no.-
int a;
a=(int)(Math.random()*21); //Typecasting to int
??(a); // print a
Comments
Post a Comment