integer

How can I pass an Integer class correctly by reference?

I am hoping that someone can clarify what is happening here for me. I dug around in the integer class for a bit but because integer is overriding the + opporator I could not figure out what was gong wrong. My problem is with this line: Integer i = 0; i = i + 1; // <- I think that this is somehow creating a new object! Here is my re...

Java question about autoboxing and object equality / identity

public class Main { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here int a1 = 1000, a2 = 1000; System.out.println(a1==a2);//=>true Integer b1 = 1000, b2 = 1000; System.out.println(b1 == b2);//=>false ...

[java] Number for each enum item?

Is it possible to define something like this in java? C# code: public enum Character { A = 1, B = 2, C = 4, D = 8 } ... Character ch = /* from user */ if(ch & Character.A) { // some operation... } for example if ch set to Character.B then result of if will be false: ch = 00000000 00000000 00000000 0000001...

How to make float values in Python display .00 instead of .0 ?

Simple question, sorry I can;t figure this out. I have some numbers that are made by float(STRING) and they are displayed as xxx.0, but I want them to end in .00 if it is indeed a whole number. How would I do this? Thanks! EDIT: Python saiys that float doesn't have a cal 'format()' ...

Why does the use of integer variables throw an exception?

Hi, I have come across with the following two codes. Why does it not throw an exception for floating point where as in other case it will throw a runtime exception. class FloatingPoint { public static void main(String [] args) { float a=1000f; float b=a/0; System.out.println("b=" +b); } ...

What is the best way to parse an Int to a Year?

I have a textbox where users can enter a year "YY" and I am parsing it using: int year; if (int.TryParse(txtYear.Text, out year)) { args.Year = year; } The problem is TryParse will convert '07' into '7' and my method is expecting the year to be in the format YYYY (e.g. input "07" should be "2007"). What is the best way to do this...

How to get the separate digits of an int number?

I have numbers like 1100, 1002, 1022 etc. I would like to have the individual digits, for example for the first number 1100 I want to have 1, 1, 0, 0. How can I get it in Java? ...

Should I use NSNumber or an int in an iPhone/iPad class?

I'm creating an object that will have two integers (or NSNumbers) and an NSDate as ivars. This object will be in an NSMutableArray. To my knowledge, we cannot put primative integers in an NSMutableArray, but will my object work with ints? The reason I don't want to use NSNumbers is because these will have to be mutable, and I don't reall...

string = string + int: What's behind the scene? (C#)

In C# you can implicite concat string and let's say, an integer: string sth = "something" + 0; My questions are: Why, by assuming fact you can implicite concat string and int, C# disallow initializing string as: string sth = 0; // Error: Cannot convert source type 'int' to target type 'string' How C# casts 0 as string. Is it 0.ToSt...

calculating factorial in Python

When calculating math.factorial(100) I get: 93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000L Why is there an L at the end of the number? ...

R - How to convert a factor to an integer\numeric in R without a loss of information

When I convert a factor to a numeric, the values change to rank values. R> m$obs [1] 0 0 1 1 1 1 3 3 3 3 3 3 3 9 9 9 9 9 9 9 9 9 11 11 12 13 13 13 13 13 13 13 14 Levels: 0 1 3 9 11 12 13 14 R> as.numeric(m$obs) [1] 1 1 2 2 2 2 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 5 5 6 7 7 7 7 7 7 7 8 I have to resort to paste() ...

How to have a bigint hash for a string

We have an alpha numeric string (up to 32 characters) and we want to transform it to an integer (bigint). Now we're looking for an algorithm to do that. Collision isn't bad (therefor we use an bigint to prevent this a little bit), important thing is, that the calculated integers are constantly distributed over bigint range and the calcul...

JavaScript Integer math incorrect results

I am just trying to implement a simple RNG in JS. What's happening is javascript evaluates 119106029 * 1103515245 to be 131435318772912110 rather than 131435318772912105. We know it's wrong since two odd numbers multiplied does not give an even number. Anyone know what's up? I just want a reliable repeatable RNG, and because of these ...

Haskell Int and Integer

Hello, What in Haskell differs from Int ant Integer? In what documentation can i find such things? Thank you ...

How to parse a string with spaces to integer

I have a string representing an integer with spaces -- digits are grouped by three. I was considering using strchr and strcat, as in: char* remove_spaces (char* s) { char* space; while (space = strchr(s, ' ')) { *space = '\0'; strcat(s, space + 1); } return s; } But, first, I'm not sure it is safe...

passing integer arguments when using execve

Hello I am a beginner at programming using system calls in C. I am trying to use the execve call in one of my programs. I have to pass an integer as an argument to the program that is being invoked through execve. However, reading on the internet and seeing sample code, I can see that we can pass only strings as arguments. So, I tried c...

Enumerating m-tuples of Integers Subject to Implication Constraints

How do I enumerate all m-tuples of nonnegative integers (a[1],...,a[m]) subject to the following constraints? For each i in {1,...,m}, there is a number n[i] >= 0 such that a[i] <= n[i]. For each ordered pair (i,j) with i,j in {1,...,m}, there are numbers c[i][j], d[i][j] >= 0 such that: if a[i] > c[i][j], then a[j] <= d[i][j]. c[i][...

how to check if the number is integer?

I was surprised to learn that R doesn't come with a handy function to check if the number is integer. is.integer(66) # FALSE The help files warns: is.integer(x) does not test if x contains integer numbers! For that, use round, as in the function is.wholenumber(x) in the examples. The example has this custom function as a "...

Java Integer - Storing mobile phone numbers??

Hi all, sorry for being such a noob first of all. I'm having trouble storing a mobile number in one of my applications. Was wondering if there is a Integer class that will allow you to store such a number starting with (0417254482) or would using a string be a more appropriate data type? At present when i try to use such a number with ...

Integer vs floating division -> Who is responsible for providing the result?

I've been programming for a while in C++, but suddenly had a doubt and wanted to clarify with the Stackoverflow community. When an integer is divided by another integer, we all know the result is an integer and like wise, a float divided by float is also a float. But who is responsible for providing this result? Is it the compiler or D...