Monday, March 30, 2015

java–Switch Case

java–Switch Case

 

 

import java.util.Scanner;
 
public class Switch {
    static Scanner a = new Scanner(System.in);
    
    public static void main(String[] args) {
        
        int b;
        System.out.println("ENter :");
        b = a.nextInt();
        switch(b)
        {
        case 1:
            System.out.println("1");
        break;
        case 2:
            System.out.println("2");
        break;
        case 3:
            System.out.println("3");
        break;
        default:
            System.out.println("4");
        }
    }
}

Java – Random

Java – Random

 

import java.util.Random;
public class randoms {
    public static void main(String[] args) {
        Random  dice = new Random();
        int a;
        for(int i = 0;i<10;i++)
        {
            a=dice.nextInt(6);    
            System.out.println(a);
        }
    }
}

JAVA- Math class Method - 1

Math.pow()

 

 

import java.util.Scanner;
public class POwer {
    public static void main(String[] args) {
 
        Scanner v = new Scanner(System.in);
        int a;
        System.out.println("Enter a number :");
        a= v.nextInt();
        System.out.println("Result is "+Math.pow(2, a));
    }
}

 


 


Math.abs();





 
public class AbsMAthClass {
 public static void 
main(String[] args) {
 
System.out.println(Math.abs(-26.3));
 }
}





        Math.ceil()
        Math.floor();
        Math.max();
        Math.min();
        Math.sqrt();





 
public class MathClassMethod {
 public static void main(String[] args) 
{
 
System.out.println(Math.ceil(26.3));
 
System.out.println(Math.floor(26.3));
 
System.out.println(Math.max(8,6));
 
System.out.println(Math.min(8,6));
 
System.out.println(Math.sqrt(25));
 }
}