You are viewing a single comment's thread. Return to all comments →
import java.util.*; public class Solution { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); String[] types = new String[]{"* byte", "* short", "* int"}; for (int i = 0; i < t; i++) { try { long x = sc.nextLong(); System.out.println(x + " can be fitted in:"); for (int k = 0; k < 3; k++) { double exponent = Math.pow(2, k + 3); // 8 bit, 16 bit, 32 bit if (x >= -Math.pow(2, exponent - 1) && x <= Math.pow(2, exponent - 1) - 1) { System.out.println(types[k]); } } System.out.println("* long"); } catch (Exception e) { System.out.println(sc.next() + " can't be fitted anywhere."); } } sc.close(); } }
Seems like cookies are disabled on this browser, please enable them to open this website
An unexpected error occurred. Please try reloading the page. If problem persists, please contact support@hackerrank.com
Java Datatypes
You are viewing a single comment's thread. Return to all comments →