![]() |
| ||
| long variable is taking integer value 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. |
| ||
| Re: why long variable is taking integer value? 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.) |
| ||
| Re: why long variable is taking integer value? 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 |
| All times are GMT -4. The time now is 1:06 pm. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC