Java Datatypes

  • + 11 comments

    We do not need to cast explicitly. We are just required to check the applicable ranges.

    if(x>=-128 && x<=127)
    	System.out.println("* byte");
    if(x>=-(Math.pow(2,15)) && x<=(Math.pow(2,15)-1))
    	System.out.println("* short");
    if(x>=-(Math.pow(2,31)) && x<=(Math.pow(2,31)-1))
    	System.out.println("* int");
    if(x>=-(Math.pow(2,63)) && x<=(Math.pow(2,63)-1))
    	System.out.println("* long");