i have written the following code and it is not executing due to the following error
dec.java:7:integer number is too large :10000000000

code

import java.util.*;
class dec{
public static void main(String args[]){
long dig,store,use,temp,temp1,end;
int count=0,count1=0,ch;
use=1000000000;
end=10000000000;
while(use<end){
dig=use;
for(int i=0;i<10;i++){
temp=dig%10;
dig=dig/10;
 ch=(10-i)%10;

store=use; 
 for(int k=0;k<10;k++){
      
       temp1=store%10;
       store=store/10;  
       if(temp1==ch)
        count++; 
  }
 if(count!=temp)              
 break;
 else count1++;
}
if(count1==10){
 System.out.println("the number is  "+use);
 break;
 }
use++;
}

}
}

i can't understand why long variable is taking integer value.

Edited 6 Years Ago by Nick Evan: Add code-tags

If you want a literal to be a long, you need to suffix it with L:

use=1000000000L;

If the literal is small enough to fit in an int, then you can write it as an int (without the "L") and it will automatically be converted to a long. But, as here, if the number is too long for an int, you need to explicitly put the "L". (The general rule is that conversions will happen automatically when the type being converted to uses the same number of bytes or more, and is NOT going from a floating point type to an integer type.)

Try this: Integer

int is 'smaller' than long so it can fit inside a long. If you write this: double d = 1; wouldn't be correct? But it is like putting an int inside a double. It will 'fit'

Also from the link provided you can find the max integer value that can fit in an int variable: Integer.MAX_VALUE

Not sure why it is giving you that error but i did find a way around it. I casted the literal number as a long and it got rid of the error. I know its only a way around it but i hope it helps. Here is the line i put in to make it work.

end=10000000000l;

i have written the following code and it is not executing due to the following error

dec.java:7:integer number is too large  :10000000000

code

import java.util.*;
class dec{
public static void main(String args[]){
long dig,store,use,temp,temp1,end;
int count=0,count1=0,ch;
use=1000000000;
end=10000000000;
while(use<end){
dig=use;
for(int i=0;i<10;i++){
temp=dig%10;
dig=dig/10;
 ch=(10-i)%10;

store=use; 
 for(int k=0;k<10;k++){

       temp1=store%10;
       store=store/10;  
       if(temp1==ch)
        count++; 
  }
 if(count!=temp)              
 break;
 else count1++;
}
if(count1==10){
 System.out.println("the number is  "+use);
 break;
 }
use++;
}

}
}

i can't understand why long variable is taking integer value.

Edited 3 Years Ago by mike_2000_17: Fixed formatting

Okay, I know NeilCoffey explained it long before, somewhat, but I, now, will still give a full explanation. It has to do with "literal" data. I.E. data that you type directly into code.

Boolean data is just that, the boolean

true   false

Strings are surrounded by quotes

"string"

If you want a char (or Character with autoboxing) you use single quotes

'c'

A literal number is somewhat different. A literal number, without a decimal point is an integer, if you want a long you need to append an L

//integer
123
//Long
123L

A literal number with a decimal point is a double, if you want a float you need to append an f

//Double
1.23
//Float
1.23f

If the lefthand variable is declared as a different type, and the literal can be "widened" to that type, no problem. If the right hand literal can not be "widened" to equal the lefthand side (i.e. the lefthand side can only hold smaller values) then you need to explicitly cast the literal, or, better, use the proper literal.

//OK
long longVar = 123;
double dVar = 123;
double dVar2 = 1.23f;  // Have no idea why you would, but hey
int intVar = (int) 123L;  // Once again, no idea why you would, but hey
float fVar = (float) 1.23;  // ditto again
//Not OK
int intVar = 123L;
int intVar2 = 1.23;
floatfVar = 1.23;
This article has been dead for over six months. Start a new discussion instead.