if statement working but not displaying output [on hold]
The code is to print that the input number belongs to which data-types. The problem is that the last if statement works but, does not print the output.
import java.util.*;
import java.io.*;
import java.lang.Math;
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();
double low = Math.pow(-2,31);
double up = Math.pow(2,31);
double low1 = Math.pow(-2,63);
double up1 = Math.pow(2,64);
System.out.println(x+" can be fitted in:");
if(x>=-128 && x<=127)System.out.println("* byte");
if(-32768<=x && x<=32767)System.out.println("* short");
if((int)low<=x && x<=(int)up - 1)System.out.println("* int");
if((int)low1<=x && x<=((int)up1 - 1) )System.out.println("* long");
}
catch(Exception e)
{
System.out.println(sc.next()+" can't be fitted anywhere.");
}
}
}
}
java
New contributor
put on hold as off-topic by Martin R, Mast, AJNeufeld, ratchet freak, Hosch250 12 hours ago
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Martin R, Mast, AJNeufeld, ratchet freak, Hosch250
If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
The code is to print that the input number belongs to which data-types. The problem is that the last if statement works but, does not print the output.
import java.util.*;
import java.io.*;
import java.lang.Math;
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();
double low = Math.pow(-2,31);
double up = Math.pow(2,31);
double low1 = Math.pow(-2,63);
double up1 = Math.pow(2,64);
System.out.println(x+" can be fitted in:");
if(x>=-128 && x<=127)System.out.println("* byte");
if(-32768<=x && x<=32767)System.out.println("* short");
if((int)low<=x && x<=(int)up - 1)System.out.println("* int");
if((int)low1<=x && x<=((int)up1 - 1) )System.out.println("* long");
}
catch(Exception e)
{
System.out.println(sc.next()+" can't be fitted anywhere.");
}
}
}
}
java
New contributor
put on hold as off-topic by Martin R, Mast, AJNeufeld, ratchet freak, Hosch250 12 hours ago
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Martin R, Mast, AJNeufeld, ratchet freak, Hosch250
If this question can be reworded to fit the rules in the help center, please edit the question.
Welcome to StackExchange sites. This question reports unexpected behavior so it's more appropriate to be asked on StackOverflow rather than CodeReview.
– dbl
13 hours ago
If it doesn't print the output while it should, why do you think it still works?
– Mast
13 hours ago
add a comment |
The code is to print that the input number belongs to which data-types. The problem is that the last if statement works but, does not print the output.
import java.util.*;
import java.io.*;
import java.lang.Math;
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();
double low = Math.pow(-2,31);
double up = Math.pow(2,31);
double low1 = Math.pow(-2,63);
double up1 = Math.pow(2,64);
System.out.println(x+" can be fitted in:");
if(x>=-128 && x<=127)System.out.println("* byte");
if(-32768<=x && x<=32767)System.out.println("* short");
if((int)low<=x && x<=(int)up - 1)System.out.println("* int");
if((int)low1<=x && x<=((int)up1 - 1) )System.out.println("* long");
}
catch(Exception e)
{
System.out.println(sc.next()+" can't be fitted anywhere.");
}
}
}
}
java
New contributor
The code is to print that the input number belongs to which data-types. The problem is that the last if statement works but, does not print the output.
import java.util.*;
import java.io.*;
import java.lang.Math;
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();
double low = Math.pow(-2,31);
double up = Math.pow(2,31);
double low1 = Math.pow(-2,63);
double up1 = Math.pow(2,64);
System.out.println(x+" can be fitted in:");
if(x>=-128 && x<=127)System.out.println("* byte");
if(-32768<=x && x<=32767)System.out.println("* short");
if((int)low<=x && x<=(int)up - 1)System.out.println("* int");
if((int)low1<=x && x<=((int)up1 - 1) )System.out.println("* long");
}
catch(Exception e)
{
System.out.println(sc.next()+" can't be fitted anywhere.");
}
}
}
}
java
java
New contributor
New contributor
New contributor
asked 13 hours ago
rogerroger
1
1
New contributor
New contributor
put on hold as off-topic by Martin R, Mast, AJNeufeld, ratchet freak, Hosch250 12 hours ago
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Martin R, Mast, AJNeufeld, ratchet freak, Hosch250
If this question can be reworded to fit the rules in the help center, please edit the question.
put on hold as off-topic by Martin R, Mast, AJNeufeld, ratchet freak, Hosch250 12 hours ago
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Martin R, Mast, AJNeufeld, ratchet freak, Hosch250
If this question can be reworded to fit the rules in the help center, please edit the question.
Welcome to StackExchange sites. This question reports unexpected behavior so it's more appropriate to be asked on StackOverflow rather than CodeReview.
– dbl
13 hours ago
If it doesn't print the output while it should, why do you think it still works?
– Mast
13 hours ago
add a comment |
Welcome to StackExchange sites. This question reports unexpected behavior so it's more appropriate to be asked on StackOverflow rather than CodeReview.
– dbl
13 hours ago
If it doesn't print the output while it should, why do you think it still works?
– Mast
13 hours ago
Welcome to StackExchange sites. This question reports unexpected behavior so it's more appropriate to be asked on StackOverflow rather than CodeReview.
– dbl
13 hours ago
Welcome to StackExchange sites. This question reports unexpected behavior so it's more appropriate to be asked on StackOverflow rather than CodeReview.
– dbl
13 hours ago
If it doesn't print the output while it should, why do you think it still works?
– Mast
13 hours ago
If it doesn't print the output while it should, why do you think it still works?
– Mast
13 hours ago
add a comment |
0
active
oldest
votes
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Welcome to StackExchange sites. This question reports unexpected behavior so it's more appropriate to be asked on StackOverflow rather than CodeReview.
– dbl
13 hours ago
If it doesn't print the output while it should, why do you think it still works?
– Mast
13 hours ago