Java Datatypes

Sort by

recency

|

1588 Discussions

|

  • + 0 comments
    import java.util.*;
    import java.io.*;
    
    
    
    class Solution{
        public static void main(String []argh)
        {
    
    
    
            Scanner sc = new Scanner(System.in);
            int t=sc.nextInt();
    
            for(int i=0;i<t;i++)
            {
    
                try
                {
                    long x=sc.nextLong();
                    System.out.println(x+" can be fitted in:");
                    if(x>=-128 && x<=127)System.out.println("* byte");
                    //Complete the code
                    
                    if(x >= -32768 && x <=  32767) System.out.println("* short");
                    if(x >= -2147483648 && x <= 2147483647) System.out.println("* int");
                    if(x >= -9223372036854775808L && x <= 9223372036854775807L) System.out.println("* long");
                }
                catch(Exception e)
                {
                    System.out.println(sc.next()+" can't be fitted anywhere.");
                }
    
            }
        }
    }
    
  • + 0 comments

    This is a great exercise to understand Java's primitive data types and their range limitations. ekbet9 com login

  • + 0 comments

    This is a great exercise to understand how Java’s primitive data types handle different integer ranges. cbtf turbo 247

  • + 0 comments

    import java.util.Scanner;

    public class Exercise3 { public static void main(String[] args) { Scanner user = new Scanner(System.in);

        System.out.println("Enter your How many \n Filtered data = ");
         int t=user.nextInt();
    
    
    
    for(int i=1;i<=t;i++)
    {
        System.out.println("Give me " + i + " number ");
        try
        {
            long x=user.nextLong();
            System.out.println(x+" can be fitted in:");
            if(x>=-128 && x<=127)
                System.out.println("* byte");
    
            if(x >= -32768 && x <=  32767)
                System.out.println("* short");
            if(x >= -2147483648 && x <= 2147483647)
                System.out.println("* int");
            if(x >= -9223372036854775808L && x <= 9223372036854775807L)
                System.out.println("* long");
        }
        catch(Exception e)
        {
            System.out.println(user.next()+" can't be fitted anywhere.");
    
         }
    
    }
    user.close();
    System.out.println("Thank you see you soon ");
    

    } }

  • + 0 comments

    import java.util.; import java.io.;

    class Solution{ public static void main(String []argh) {

        Scanner sc = new Scanner(System.in);
        int t=sc.nextInt();
    
        for(int i=0;i<t;i++)
        {
    
            try
            {
                long x=sc.nextLong();
                System.out.println(x+" can be fitted in:");
                if(x>=-128 && x<=127)
                    System.out.println("* byte");
                //Complete the code
                if(x >= Short.MIN_VALUE && x <= Short.MAX_VALUE)
                    System.out.println("* short");
                if(x >= Integer.MIN_VALUE && x <= Integer.MAX_VALUE)
                    System.out.println("* int");
                if(x >= Long.MIN_VALUE && x <= Long.MAX_VALUE)
                    System.out.println("* long");
            }
            catch(Exception e)
            {
                System.out.println(sc.next()+" can't be fitted anywhere.");
            }
    
        }
    }
    

    }