We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Help me out with this code, i dont know why the error happens only if the entered number suits only long datatype...kindly please do help me out to solve this code.
import java.util.*;
public class datatype{
public static void main(String[] args){
Scanner pr=new Scanner(System.in);
int t=pr.nextInt();
int count=0;
String a[]=new String[t];
for(int i=0;i
try {
long a1=Long.parseLong(a[j]);
if(-9223372036854775808l<=a1 && a1<=9223372036854775807l){
count=1;
System.out.println(a[j]+" can be fitted in:");
int b=Integer.parseInt(a[j]);
if(-128<=b && b<=127){
System.out.println("* byte");
}
int c=Integer.parseInt(a[j]);
if(-32768<=c && c<=32767){
System.out.println("* short");
}
int d=Integer.parseInt(a[j]);
if( -2147483648<=d && d<=2147483647){
System.out.println("* int");
}
System.out.println("* long");
}
} catch (Exception e) {
// TODO: handle exception
if(count==0){
System.out.println(a[j]+" can't be fitted anywhere.");
}
}
count=0;
}
pr.close();
}
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Java Datatypes
You are viewing a single comment's thread. Return to all comments →
Help me out with this code, i dont know why the error happens only if the entered number suits only long datatype...kindly please do help me out to solve this code.
import java.util.*; public class datatype{ public static void main(String[] args){ Scanner pr=new Scanner(System.in); int t=pr.nextInt(); int count=0; String a[]=new String[t]; for(int i=0;i
}