Java Datatypes

Sort by

recency

|

1553 Discussions

|

  • + 0 comments

    hey i dont know why the code is not running properly :

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

    public class Solution {

    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 sc = new Scanner(System.in);
        int t = sc.nextInt();
    
        for(int i = 0; i < t; i++){
            try{
                long a = sc.nextLong();
                System.out.println(a+" can be fitted in:");
    
                if(a >= Byte.MIN_VALUE && a <= Byte.MAX_VALUE){
                    System.out.println("* byte");
                }
                if(a >= Short.MIN_VALUE && a <= Short.MAX_VALUE) {
                    System.out.println("* short");
                } 
                if(a >= Integer.MIN_VALUE && a <= Integer.MAX_VALUE){
                    System.out.println("* int");
                }
                if (a >= Long.MIN_VALUE && a <= Long.MAX_VALUE) {
                    System.out.println("* long");
                }
            }catch(Exception e){
                String x = sc.next();
                System.out.println(x+" can't  be fitted anywhere.");
            }
        }
        sc.close();
    }
    

    }

  • + 0 comments

    Dogs are naturally active and need regular exercise to stay physically and mentally healthy. Regular walks, playtime, and interactive activities keep them fit and help maintain a healthy weight. Mental stimulation is equally important as physical exercise to prevent behavioral problems Dog Food Supplements. Engaging dogs in training sessions or puzzle toys can help keep their minds sharp and reduce anxiety or boredom-related behaviors.

  • + 0 comments

    It's just a try for using another method

    import java.util.Scanner;

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

        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>=-127 && x<=128){
                    System.out.println("* byte");
                }
                if(x>=Math.pow(-2,31) && x<=Math.pow(2,31)-1){
                    System.out.println("* short");
                }
                if(x>=Math.pow(-2,16) && x<=Math.pow(2,16)-1){
                    System.out.println("* int");
                }            
                if(x>=Math.pow(-2,64) && x<=Math.pow(2,64)-1){
                    System.out.println("* long");
                }
    
            }
            catch(Exception e)
            {
                System.out.println(sc.next()+" can't be fitted anywhere.");
            }
    
        }
    }
    

    }

  • + 0 comments

    import java.util.Scanner;

    public class Solution {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int t = input.nextInt();
    
        for (int i = 0; i < t; i++) {
            try {
                long num = input.nextLong();
                System.out.println(num + " can be fitted in:");
                boolean canFit = false;
    
                if (num >= Byte.MIN_VALUE && num <= Byte.MAX_VALUE) {
                    System.out.println("* byte");
                    canFit = true;
                }
                if (num >= Short.MIN_VALUE && num <= Short.MAX_VALUE) {
                    System.out.println("* short");
                    canFit = true;
                }
                if (num >= Integer.MIN_VALUE && num <= Integer.MAX_VALUE) {
                    System.out.println("* int");
                    canFit = true;
                }
                if (num >= Long.MIN_VALUE && num <= Long.MAX_VALUE) {
                    System.out.println("* long");
                    canFit = true;
                }
    
                if (!canFit) {
                    System.out.println(num + " can't be fitted anywhere");
                }
            } catch (Exception e) {
                System.out.println(input.next() + " can't be fitted anywhere."); // Clear the invalid input
            }
        }
        input.close(); // Close the scanner to prevent resource leaks
    }
    

    }

  • + 0 comments

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

    class Solution{ public static void main(String[] args) { 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 >= Byte.MIN_VALUE && x <= Byte.MAX_VALUE)System.out.println("* byte");
            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.");
        }
    
    } 
    sc.close();  
    

    } }