From 87619b626155c874ee27d913346e2f0a3721050f Mon Sep 17 00:00:00 2001 From: shivam patidar <104291786+mrshiv97@users.noreply.github.com> Date: Fri, 15 Jul 2022 18:40:30 +0530 Subject: [PATCH] Update JavaDatatypes.java --- Java/Introduction/JavaDatatypes.java | 56 +++++++++++----------------- 1 file changed, 22 insertions(+), 34 deletions(-) diff --git a/Java/Introduction/JavaDatatypes.java b/Java/Introduction/JavaDatatypes.java index b80ecee..c23a49b 100644 --- a/Java/Introduction/JavaDatatypes.java +++ b/Java/Introduction/JavaDatatypes.java @@ -26,41 +26,29 @@ import java.io.*; import java.util.*; -import java.text.*; -import java.math.*; -import java.util.regex.*; - -public class JavaDatatypes { - - static String whoCanFitTheNumber(String numString) +class Solution{ + public static void main(String []argh) { - String answer = ""; - try{ - long num = Long.parseLong(numString); - answer = numString + " can be fitted in:\n"; - if((num<=Byte.MAX_VALUE) && (num>=Byte.MIN_VALUE)){ - answer = answer.concat("* byte\n* short\n* int\n* long"); - }else if((num <= Short.MAX_VALUE) && (num >= Short.MIN_VALUE)){ - answer = answer.concat("* short\n* int\n* long"); - }else if((num <= Integer.MAX_VALUE) && (num >= Integer.MIN_VALUE)){ - answer = answer.concat("* int\n* long"); - }else{ - answer = answer.concat("* long"); + Scanner sc = new Scanner(System.in); + int t=sc.nextInt(); + + for(int i=0;i=-128 && x<=127)System.out.println("* byte"); + if((x <= Short.MAX_VALUE) && (x >= Short.MIN_VALUE)) System.out.println("* short"); + if((x <= Integer.MAX_VALUE) && (x >= Integer.MIN_VALUE))System.out.println("* int"); + if((x <= Long.MAX_VALUE) && (x >= Long.MIN_VALUE))System.out.println("* long"); } - }catch (NumberFormatException e){ - answer = numString+" can't be fitted anywhere."; - } - return answer; - } - public static void main(String[] args) { - /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. - */ - Scanner scanner = new Scanner(System.in); - int numTestCases = scanner.nextInt() ; - scanner.nextLine(); - for(int i=0; i