# Komal Arora

Ranch Hand
since Sep 30, 2010
Komal likes ...
For More
Cows and Likes
Cows
0
In last 30 days
0
Total given
0
Likes
3
0
Total given
2
Given in last 30 days
0
Scavenger Hunt
Ranch Hand Scavenger Hunt
Greenhorn Scavenger Hunt

## Recent posts by Komal Arora

Campell Ritchie:

I had 10 mins to solve the problem so the first thing that came into my mind was to traverse the list and store the values as string so that they can be reversed later and then converted to numbers and added. But i do understand that i am using strings when the question tells me to use int values. Will work on that.

Joanee Neal:

Thanks for the suggestion. I will try to code it like you said.

11 years ago
Hi Guys,

I came accross an interview question which goes like this:

"You have two number represented by a linked list, where each node contains a single digit. The digits are stored in reverse order, such that the 1's digit is at the head of the list. Write a function that adds the two numbers and returns the sum as a linked list"
example:
Linked list 1: 7 -> 1 -> 6
Linked list 2: 5 -> 9 -> 2
The numbers would be: 617 and 295

output: 617+295 = 912

------------------------------------------------------------

Now i have written the following function to implement the above problem. The code works fine and i am getting the output.
I want to know from you guys whether the way i have programmed is nice or not? I keep getting feedbacks that my code is not "clean". can you please give me honest comments on the coding style.

The Node class is as follows: I am pasting it because the previous method uses the getNext() method.

Thanks,
Komal
11 years ago
Ok Got the error

It should have been Character.toString(arr[i]) rather than arr[i].toString() !!!

11 years ago
As For BigInteger Class. I went through that and all i understood was that it converts Strings into ints of arbitrary length. But we cannot apply usual arithmetic operators on these ints. quite obvious. But then how do i manipulate that big number. I did not understand the methods of that class pretty well! I will try to explore it more.
11 years ago

Winston GutkowskiAs Matthew said: sounds perfectly reasonable; and that first bit can be done in one line with BigInteger. And if you have a String, then the second part of that idea is theoretically redundant, because String has a [tt wrote:charAt(int)[/tt] method; although a for-each loop using String.toCharArray() might be more readable.

I tried this:

I am getting an error : Cannot invoke toString on the primitive type char. Why is this coming? What am i doing wrong?

11 years ago

Matthew Brown wrote:You need to have a look at the BigInteger class. That stores integers of arbitrary size.

That particular Project Euler problem is trivial in languages that have a BigInteger type or similar. You've got to go to much more trouble if you don't have it - think about how you might implement your own BigInteger if you had to!

Can i manipulate numbers declared as BigIntegers by the simple Arithmetic operators?
11 years ago
Ok i would have a look at the BigInteger class.

Yes, calculating the sum with double would give wrong values because of the precision..

I was thinking of another alternative. What if i store the value of 2^1000 as a String. Then i convert it to a character array. Then i calculate the sum of all the digits by visitng each element in the char array and adding it. Would this work? or is this really bad programming?
11 years ago
i made a java project for image classification algorithms.
I used the java advance imaging API. This API would give you many inbuilt methods which you can use to easily implement many image processing algorithms.
11 years ago
Hi,

I am currently working on the problems of Project euler [webpage]
There is one problem in which we have to calculate the sum of all digits of 2^1000
The result comes out to be huge! How should i proceed with the calculation of the sum of digits of such a huge number?

For small numbers i calculate the sum of digits using the following code:

now the value of 2^1000 is so big that it cannot be stored as an int. If i store it in a double, then how would i calculate the sum?

11 years ago
i use ide's for development so there is no question saving files in bin. i did that bin thing when i ran my first java program.

For all the things said. i'm sorry. thats all i have to say.
11 years ago
you know what he is a beginner in java, and when i was a beginner i learned the same way and hence i told him to do so. this is not misleading advice.

and no offence, but i feel that people here are more concerned about what others are saying rather than giving their own opinions! Really no offence, but it would be just fine to give your own ideas and let other people give their own ideas as well, unless and until someone write offensive stuff. there is no harm in it, right? It does not look nice when you point out somebody telling that he/she is giving misleading advice. Sorry i am writing this way but i just have seen to0 much of this recently.

11 years ago

Campbell Ritchie wrote:

Komal Arora wrote: . . . save it as a .java file in the bin folder of jdk. . . .

Yes i know. But the person who posted it seems to be a beginner and hence i just told how to get started with java.

Using your own folders SHOULD be followed everytime!
11 years ago
You can do the following:
1) you input the text file, use readLine() to read the lines in the text file one by one.
2) after that you can use stringTokenizer class. You get two tokens at each line.
3) Store the tokens in a data structure. for eg tree map: TreeMap<String, Integer> = new TreeMap<String, Integer>();
4) once you have all the values in the tree map, you can just get the value for a particular string. The map would have entires like: Located, 1 ; biosphere 2 and so on.
So for Located you will get the value 1.

I did this for my project. I had a text file with some numerical values which were required for some calculation. So i read the file, used StringTokenizer to get the tokens and stored them in the tree map.

11 years ago
update the environment variables in your system.
write the simple hello world program in notepad.
save it as a .java file in the bin folder of jdk.
go to cmd.
go to the path where your jdk bin is.
it's usually C:\program files\java\jdk\bin
write "javac filename.java" to compile your file
write "java filename" to run your file.

hope it helps
11 years ago
yeah run the code. that would make all things clear.

For arrays, the rules remain the same.
try out this:

11 years ago