# Integer 5 « Integer « Java Data Type Q&A

### 1. Encoding an decoding -ve integers    forums.oracle.com

&0xff)<<24)|((b[i+1]&0xff)<<16)|((b[i+2]&0xff)<<8)|(b[i+3]&0xff); i += 4;}; //System.out.println(value); If i give -100 as input it is giving 28 as output..by taking 2's complement i think...but i want it to recognise as -100 and encode it...plzz help me in this regard....How do i modify the encoding and decoding code above to handle -ve integers.....???? regards kiran

### 2. Largest integer program?    forums.oracle.com

This is what I've done so far: public class UwagzKa { public static void main (String[] args){ int a = 0; int min = 0; int max = 0; int num = 0; do { System.out.print("Enter numbers-->"); num = SavitchIn.readLineInt(); if(num==0) System.out.println("Numbers must be positive"); } while(num>0); while(num>0) if (num > 0){ min = num; max = num; } else if ...

### 3. Finding duplicate entries in an int[]    forums.oracle.com

Okay, So I need to solved the following problem. Given an int[] or Integer[] with 1,000,000 entries. There are 2 entries out of the 1,000,000 that are duplicate. I need to find and return the duplicate entry. Obviously iteration is out of the question given the size of the array, and converting to an arraylist would likewise not help alot. Please ...

### 5. Problem with a key pushed and an int that increases    forums.oracle.com

Hey, I'm working on an checkers game and I'm trying to switch between my black and white checker by letting an int increase by pushing the SpaceBar. My problem is that when I use my mouse or press another key then the spacebar the int increases. I'm working by MVC so I my controller is: public void keyPressed(KeyEvent e) { switch ...

### 12. Int cannot be dereferenced    forums.oracle.com

First off, it's nice that you used the code tags, but clean up your indentation. Now then, ints are primitives. As such, they are not reference types and cannot be the target of method invocations. Go to the line number specified in your error message. Somewhere on that line, you are trying to call a method on a variable of type ...

### 18. A question about immutable object: Integer    forums.oracle.com

One could argue for the precision of such convoluted explanations of pass by value. The statement "Java is pass-by-value" isn't convoluted at all. It's not only the way Java actually works, it's the simplest explanation. Any other "explanation" requires all kinds of exceptions and special cases, and is ultimately incorrect. when you say Integer i = new Integer(); So youre not ...

### 19. Setting so that Integers produced by program must = or > 0?    forums.oracle.com

On my payroll program, I'm getting really close to what I need...the only thing is, certain values that are calculated by my program could potentially come out negative. The assignment requires that some of these values (taxable income, tax rate, paycheck) must always be equal to or always 0. So if the variables inputted produced a negative number, the program would ...

### 21. How do I determine if an inputed integer takes the form of a^b for b>1    forums.oracle.com

I am trying to write a program that uses the ASK prime test algorithm, as described here. How can I test to see if an inputted integer is made up of one same number multiplied a whole bunch of times? Example: 625 takes the form of a^b because 625=5x5x5x5= 5^4 88 does not take the form of a^b because 88=2x2x2x11=2^3x11 It ...

### 27. integer display program    forums.oracle.com

public void Display() { System.out.println("The integer is " + no); } } UtilShow.java file import java.io.*; public class UtilShow{ public static void main(String[] args) { InputStreamReader isr = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(isr); Show one = new Show(); System.out.print("Input the integer: "); one.show(br.readLine()); one.Display(); } } Please help. Thanks alot!

### 28. why we can not initialize Integer object    forums.oracle.com

You shouldn't be questioning the compiler. When you ask a question like this it implies that you're thinking "I'm doing everything correctly; why is the compiler acting so strangely?" Any time you get an error from the compiler, believe it. It means that YOU did something wrong. Go back and look at the javadocs, because it usually means that you're assuming ...

### 31. int question    forums.oracle.com

Hi, This is actually more for my mum than me (bizarrely enough). Basically she has a program that stores telephone numbers (for a class - not for real) She's storing uk area codes using ints and is trying to say something along the lines of: int areaCode = 0141; Apart from the obvious fact that you would use a String to ...

### 32. Stuffing two shorts into an int    forums.oracle.com

Normally I would agree with you. However, this is the only way I can make a system I am working on compatible with a legacy system. The new system will stuff two shorts into an int for the legacy system, and then when the new system gets the same data back, it will need to recover the two shorts from the ...

### 33. Int cannot be dereferenced    forums.oracle.com

hi im pretty new to java and i write an event-handler and i get the message rekenmachineApplet.java:94:13: int cannot be dereferenced i'll send the event-handler. rekenmachineApplet.java:94:13: int cannot be dereferenced public void plusKnopActionPerformed(ActionEvent evt) { int getal1; getal1 = Integer.parseInt(getal1Veld.getText()); int getal2; getal2 = Integer.parseInt(getal2Veld.getText()); int getal3; getal3 = (getal1 + getal2); int getalVeld; getalVeld.setText(getal3); }

### 34. Increment Integer object    forums.oracle.com

Ok, I will probably get told off for this question, called a n00b or whatever and told to read stuff. I've looked and havent found anything or I've just missed it. I'm storing keys and values in a map (abviously). The map just stores sizes. I have a main list. Joe might have 10 items on the list and Kate might ...

### 35. Int Placemarker?    forums.oracle.com

Hey, I am writing a program and I started by putting all the numbers in strings. The reason they are in strings is because I need to later pick out specific characters. I need a number such as 25 to be 025 or 0025 to hold its place depending on what I set it at. The thing is, when I parse ...

### 36. Print Ascending or Descending Integers on one line.    forums.oracle.com

1) remove these codes inside "switch(order)" System.out.println(); // this cause printing of extra line 2) change System.out.println(numberTwo); // the println print an line after every number System.out.print(numberTwo+" "); // print only a space after every number and do the same for numberOne. 3) final codes for numberOne System.out.print(numberOne+" "); numberOne = numberOne + 1; Edited by: lazy_programmer on Oct 16, 2007 ...

### 38. A basic text/string equality question    forums.oracle.com

Text myField; System.out.println((myField.getText() == "x")+ " because:>" + phoneField.getText() + "< is different than: x"); The result is the following printed to my console false cause: >x< is different than: x How can this be that "x" doesn't equal "x"? I thought maybe a text object doesn't resolve to a string but casting with (String)myField.getText doesn't change the outcome either. I'm ...

### 39. A simple Type Casting/Equality question    forums.oracle.com

Hi guys... This is my first post! What is the difference between these two code fragments that give different outputs? 1. Integer a = 200, b = 200; System.out.print(a==b); //returns false - as I expect 2. Integer a = 20, b = 20; System.out.print(a==b); //returns true - as I do not expect Note: The threshold value for variables is 128! Output ...

### 40. Set a pixel int in buffered image    forums.oracle.com

Hi, iam writing a program in which i would like to set the value of a pixel in a BufferedImage. I have managed to extract a pixel from the BufferedImage and also get the red, green and blue values from this pixel (confusing in itself). Now I am wanting to change those values and convert the three individual ints (red, green ...

### 41. To determine the no. of leading 0's in an int    forums.oracle.com

Hi, I'm trying to determine the no. of leading 0's in an int. I have something like: int num = 000012345; And for this i want the result to be 4. Is there a way for me to achive this without actually converting my int into a String ? Pls advice. Note: I tried using Integer.numberOfLeadingZeros(). But i'm getting the result ...

### 42. PixelGrabber.getPixels returns an int[] full of -1's    forums.oracle.com

It returns an int[] of nothing but -1 Yes, the image is 1280x960, so it is definitely within the bounds. What I'm trying to do is take a screen shot, which I know worked because I can set it as an icon or save it to a file just fine. Within that screen shot I'm trying to read certain areas of ...

### 45. changing int into object    forums.oracle.com

if you need to add int primitive to ArrayList or any other structured data type you have no need to cast to Object as Onject extends every other object so you should be able to add the Integer object to your arraylist or whatever. As I said I see no need in casting Integer class instances to Object instances.

### 46. int[] or List?    forums.oracle.com

How many ints make up one char according to your codec algorithm? It's up to the user. Encapsulate the array of integers in a class that is more meaningful, and provide that class with equals and hashCode methods. Then use this class instead of an array in the Map. Yeah, I'd thought about that, but wasn't especially fond of the idea, ...

### 47. Integer!    forums.oracle.com

is there anyway we can set an integer to null? For example: int manufacturer_id =Integer.parseInt(request.getParameter("idtf")); if(manufacturer_id!=null){ out.println("hello!"); } I will always get an error saying that it is incompatible type. so i will have to code it this way: if(manufacturer_id != 0) but this is not effective, unless a person type 0 but not other thing then it will go into ...

### 49. problem in reading integers data    forums.oracle.com

hi all, i'm reading integers from console and storing them in a file and then reading back, but my data is inconsistent.can anybody tell me the reason for this. heres my code snippet... DataInputStream in = new DataInputStream(System.in); DataOutputStream out = new DataOutputStream(new FileOutputStream("intdata.txt")); try{ int a = in.readInt(); out.writeInt(a); out.close(); in.close(); }catch(EOFException eofe){ throw new RuntimeException(eofe); } DataInputStream in2 = ...

### 51. search the integer    forums.oracle.com

Hi guys can anybody help me with this one? I have a file with one string or integer in each line. Now i have to search the highest and lowest number from the file and print it to the console. I know i have to assume each string as an integer, but i don't how to code them. my file (findInt.dat) ...

### 53. Find the closest Integer to a given Integer in a Vector/List    forums.oracle.com

Most of these biggest/smallest/greenest/etc problems are got at the same way: (1) Start with a sensible value for the "result". Often the first element of the list. (2) Write a loop that goes through the list. Compare the list item with the result to see if it is bigger/smaller/greener/etc. If it is it can replace the result. (3) Once the loop ...

I want to get a list of the table VwOdaycount ,the list should contain the fday (taken as the key word of the list) and the fcount(taken as the object of the list). the HQL is ""select model.fday,model.fcount from VwOdaycount as model where model.fitemId="+itemID + "and model.fyear=" +year +"and model.fmonth="month"order by model.fday asc"; " using the Hibernate version:3.01 failure Trace is ...

### 55. least common multiple for multiple integers    forums.oracle.com

Warnerja, thanks for the instant reply. I thought of this: from LCM(LCM(a, b), c) we can get a common multiple for a, b, c. but can we ensure this common multiple is least? LCM(a, b, c) == LCM(LCM(a, b), c) -> is this proven by math theory? (I am not good at math, so not sure)

### 56. effective integer maximum    forums.oracle.com

Hello, Am I correct in saying that the integer maximum is 0xFFFFFFFF or is it something less than that? Or does it vary by machine? Is there some global variable/function I can call up and just get it without having to define it myself? The reason is that I have a counter type variable that I expect to get up very ...

### 58. Entering integers    forums.oracle.com

Hi this is my first yr using java and I am so confice so I need some help. I need to do a program where the user needs to input an integer of 3 digits but if the user enter less or greater then 3 digits the program needs to return an error message. I need to do it with out ...

### 59. Ascending Integers    forums.oracle.com

yeah normally assignments (well at my school) will want you to adapt methods learnt in the weeks prior to the assignment. Although, i know one of the first things i learnt was how to use the API... which was also part of my first assignment so maybe you could. Should ask the teacher though incase i guess

### 60. Type safety: The method add(int, Object) belongs to the raw type List. Refe    forums.oracle.com

ok many thanks for your help!! I'm having a graph with several nodes and want to store the values of their attributes in Lists. The data types of these attributes are String, Double, Char. First of all I wanted to build a List containing all x-coordinates of the nodes which are double

### 62. Which is better int or Integer ??    forums.oracle.com

Hi, java supports both primitives and objects. int is a primitive, Integer is an object. int is a just simple integer type, which comes from c++ or c or whatever it has nothing to do with objects, simple. On the other hand Integer is a huge fat class, which has many usefull methods such as coverting to String and to other ...

### 63. I need some Help with using Big Integers    forums.oracle.com

I asked a lot of ppl how to do this but they told me to do it either in Vectors or in Arrays. I don't know any thing about Vectors and just basicly understand Arrays. I would rather do this in Arrays than in Vectors. I would Appreciate any help that I can get. Thank You.

### 64. Problem instatiating Integer    forums.oracle.com

If I try to compile I get the following error: "unexpected type found: type parameter Integer required: class" My JDK version is 1.5.0.04 I haven't seen this problem in the forums. Everything that I've read indicates that this is legal; What am I missing? I've been looking at this so long that my eyes are crossed.[

### 65. Fundamental Question about int vs Integer    forums.oracle.com

The basic answer is that int is a primitive, and Integer is a class. Integer is a wrapper for ints, meaning it was designed to allow you to conveniently use a primitive int where only objects were allowed. Java 5 has a feature called autoboxing that allows you to use them somewhat interchangably.

### 67. Object storing an int    forums.oracle.com

(This is from a previous post about the bus) For the Queue class (and in general) when I want to add to my list I must pass in an object. How do I encapsulate an integer in the object and how can I compare the object (as an integer) to another interger? Thanks for all your help, sorry I'm a beginner. ...

### 68. displaying null when trying to read integer type from excell sheet    forums.oracle.com

Connection C=DriverManager.getConnection("jdbc:odbc:mydsn3"); out.println("Connected: " + !C.isClosed() + "\n"); out.println("Catalog: " + C.getCatalog() + "\n"); Statement S = C.createStatement(); ResultSet rs = S.executeQuery("SELECT * FROM [Sheet1\$]"); //ResultSet rs = S.executeQuery("SELECT * FROM [test\$]"); ResultSetMetaData rsStruc = rs.getMetaData(); out.println("Table: " + rsStruc.getTableName(1) + ""); out.println("

"); out.println(""); int colCount = rsStruc.getColumnCount(); String colName = "";

### 69. Adding To and Removing From an Integer List    forums.oracle.com

Add a method void removeFirst(int newVal) to the IntegerList class that removes the first occurrence of a value from the list. If the value does not appear in the list, it should do nothing (but it's not an error). Removing an item should not change the size of the array, but note that the array values do need to remain contiguous, ...

### 71. problem with passing a integer!!!!!    forums.oracle.com

Captain answered your question despite the whining the !!!! imply, not because of it. People here are not impressed with stupid little tricks to "get our attention" like !!!!! and PLZZZZZZZZ and URGENT. That **** is just annoying and detracts from your message. If you want the best help possible, as soon as possible, then you should focus on clearly, concisely, ...

### 72. a method that returns an int etc    forums.oracle.com

hey guys i need help creating a group of the following methods that can be used to hide a JOptionPane code: getInt Returns an integer value getDouble Returns a double value getString Returns a string outputMessage Outputs a messge via a JoptionPane i also need write a main that will demonstrate the use of these four methods.

### 74. using an int from one class in another class    forums.oracle.com

I am a student writing a java program on renewable energy. Simply I have a power output which is a variable called PowerOutPut. declared as (public int PowerOutPut) I have another class which is a graphics class where I display the variable PowerOutPut on a graph, but i dont know how to call this variable in my graphics class. if anyone ...

### 76. integer help    forums.oracle.com

So where exactly did the OP say anything about binary? As was listed in another post the standard way to count the digits is to successively divide by 10. Since integer math truncates a number like 137 divided by 10 becomes 13 and divided by 10 again becomes 1 and divided by 10 again becomes 0. When you hit zero you ...

### 79. Squaring and cubing an integer    forums.oracle.com

im fairly new to java and i was wondering if someon could help me out with squaring and cubing a number in java example 5, how would you go about doing this where the Main(method) prints the results. The number goes through each method squared and cubed, just wondering if anyone could post maybe an example?

### 81. int cannot be dereferenced    forums.oracle.com

int roomB, finAid, vaResident, Rboard, studentID, creditHrs; int partTime, fullTime,fees, subtotal, total; fees = 796; String ysno1,ysno2,ysno3, ysno4; String name = ""; String board = ""; String room = ""; String Aid = ""; Scanner scan = new Scanner (System.in); do { System.out.print ("Enter student's ID number: "); studentID = scan.nextInt(); if (studentID ==-1) {return;} System.out.print ("Enter Students's Name: "); name ...

### 82. Storing integers in a compiled program    forums.oracle.com

I would am wriitng a program and I would like to generate a unique number for each time a users uses the compiled program, is it possible to store previously incremented numbers i.e. the last person who used this program got a print out number of 5. The next person to use this program would then get the number 6 etc ...

### 83. Help with bitmapped int    forums.oracle.com

Hi! I use a method that returns a bitmapped int that contains a version number. I want to convert the int to a "readable" format. According to the documentation: Format of version number is as follows: Bits 31-28 major version number Bits 27-24 minor version number Bits 23-16 patch or service pack level Bits 15-0 build number Example of the int ...

### 84. Making int global??    forums.oracle.com

There's no such thing as a "global" variable in Java. There are local variables and member variables, with members being further broken down into instance variables (non-static member variables) and class variables (static member variables). You'll want to study the three closely and make sure you understand what their respective roles are. Here's a quick summary: instance variables: Used to represent ...

### 85. UI Field showing only integers    forums.oracle.com

sparrowDCLXVI wrote: If the initial value is 600,000, and I delete the 6, the field shows 0. I cannot delete this zero so that the field is empty, which I need to do. If I delete the zeros one after the other, I am left with a 6 that I can't delete. This is not good, because to update the field ...