Can anyone tell me why it is giving error, while using long datatype
long x = sc.nextLong();
if (x < 9223372036854775807L && x > -9223372036854775808L) {
System.out.println("* long");
}
To specify a numeric literal as a long instead of an int , add an L (for long) to the end of the literal. Without "L" in the end, the compiler is identifying the numbers as integers and the specified integers in the if statement are out of bounds of an Integer.
Java constant is out of range
In order to write a long literal you need to add an L
to the end of the number. Try
public static final long MAXMONEY = 1000000000000000000L;
I did not test, if this number is small enough for a long.
09 is not recognized where as 9 is recognized
In java, if you are defining an integer, a leading '0' will denote that you are defining a number in octal
int i = 07; //integer defined as octal
int i = 7; // integer defined as base 10
int i = 0x07; // integer defined as hex
int i = 0b0111; // integer defined as binary (Java 7+)
int 0801 out of range
A number starting with 0 is in octal base and you can't use the digit '8' in it.
Project Euler #3 out of integer range java
600851475143 of type int is out of range
- This number is bigger than
int
can store. Appending.0
to the number converts the number into adouble
which can represent that number - Instead of
.0
you can docheckFactors(600851475143d)
which ensure the number is a double and not an int
Unable to insert values in database The resulting value is out of range for the DECIMAL / NUMERIC data type (3.1)
stmt.execute();
is too much, and indeed might have caused an "erroneous" error.
The last stmt = conexao.prepareStatement(sql);
too.
The MySQL reference might help. DECIMAL(3, 1) has range -9.9 .. 9.9.
This might a correct scale, otherwise you maybe intended DECIMAL(5, 2).
nota
might be checked.
As floating point (double
) is imprecise, it might even be better to use BigDecimal
(fixed point) on java side.
System.out.println("And finally, type your grade: ");
BigDecimal bdnota = ler.nextBigDecimal();
// Check input: scale and digits
System.out.println("Scale: " + bdnota.scale());
stmt.setBigDecimal(3, bdnota);
Mark literal as 32bit
How about:
MyVar = 329& + 100&
Related Topics
What's the Syntax for Mod in Java
Java' Is Not Recognized as an Internal or External Command
How to Handle Windows File Upload Using Selenium Webdriver
How to Access an Iteration-Counter in Java's For-Each Loop
What Does Statement.Setfetchsize(Nsize) Method Really Do in SQL Server Jdbc Driver
Generate All Combinations from Multiple Lists
Parsing an Arithmetic Expression and Building a Tree from It in Java
Java Count Occurrence of Each Item in an Array
Cannot Issue Data Manipulation Statements with Executequery()
Java Method to Swap Primitives
Jersey /* Servlet Mapping Causes 404 Error for Static Resources
Java.Io.Console Support in Eclipse Ide
What Operations in Java Are Considered Atomic
Transitive Dependencies Not Resolved for Aar Library Using Gradle
Android: How to Stretch an Image to the Screen Width While Maintaining Aspect Ratio