Nazma Panjwani

Greenhorn
+ Follow
since Jan 17, 2010
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Nazma Panjwani

I am reading input from a file that has following information:
line 1 = numbers of integers in array,
line 2 = elements in array1,
line 3 = elements in array2.
These lines constitute a test case. There are 1000 test cases in the input file.
So basically, I read the length of arrays, populate the arrays by reading from the file.

The code is below ( I have not included reading input code):


Array2 is populated using the same as above code. However when I use the following code:




I get " local variable vector1 and vector2 have not been initialized error". But both arrays have been initialized in the if{} block. Is it because initialization was local to if block? How do I get around this problem?
9 years ago
I have a Matrix class whose constructor throws an IllegalArgument exception if the matrix dimensions are not right. The exception is being caught in my main method. An odd thing happens when I put try-catch block though. If I create a matrix object (valid dimensions are passed) and put it in a try block, once the code goes past the catch block, the matrix object can no longer be referenced. The compiler issues an error that the symbol does not exist. Look below at my code please. The error goes away if I remove the try-catch block.
10 years ago
John,

I don't come to Java Ranch to get my assignments done. I am doing this problem just out of curiosity and trying to reinforce the concept of Recursion, a concept that I find difficult to understand. Hence, I specifically decided to do this problem using recursion, but eventually lost my patience trying to figure out the solution.

Thanks for your help


Nazma
13 years ago
Hi,

I am trying to write a recursive method for determining if a string is palindromic. I have the code as follows:

String S = "radar";
int left = 0;
int right = S.length()-1;


public static void palindrome (int left, int right)
{

if (left < right || left==right)
{

if (S.charAt(left)==(S.charAt(right)))

palindrome (left+1, right-1);
}

}

I tried setting the return type to boolean, in order to indicate if the string is palindromic, but the method kept returning true (regardless). Recursion is such
a hard concept to grasp, can someone add some code to this method so it would return true depending on whether the string is palindromic, and hence
be able to print using println method?

Thanks
13 years ago
Hi,

What does this statement mean....In Java, a while loop cannot have an empty condition but a for loop can. Can you give examples please???


Thanks
13 years ago
Thanks it works, I just changed the reference variable name. Actually, I am supposed to catch the same exception that I am throwing.......Thanks again
14 years ago
Hi Guys,

I created this class StringTooLongException, which extends the exception class, then I created another class which basically takes in user input, and if string is too long (more than 20 characters), StringTooLongException is thrown.


here is the idea

so if exception is thrown program terminates.
Now, in another project, I am supposed to catch the exception and print the message.
so when I put the if-else statement under try block, and then there is a corresponding catch block..........it doesn't work......I only know how to catch exceptions that are
built into Java like Arithmetic exception.......
Anyways, compiler says "StringTooLongException" is already defined in main......what am I doing wrong??? How do I catch the exception???


Thanks
14 years ago
Guys,
Please tell me what I am doing wrong,
I created an input file, called inventory.dat, saved in under the same package, as the following class, please see the code blelow,
basically, the programs reads an input from the file, makes objects, saves them in an array, and prints them; the input file just has
item, units and price llisted on each line. I dont have any syntax errors, the programs runs properly, but there is not output produced. Is it
not reading from the file??? It is not even throwing any exceptions.

Thanks.
14 years ago
Hi Guys,

I am trying to create a text data file, file extension .dat.....how do I do this??
Basically, I am supposed to write a class in java, that reads from this text file, (the text file contains inventory information such as item name, # of units, price etc), and creates objects (of some class type which I am also supposed to create). So, taht's two classes........

Can I create a wordpad file, and change the extension to .dat???

Thanks
Nazma
14 years ago
Thanks guys,

Joe it was an assignment, so I had to come up with my own class.....and array........couldn't use ArrayList,
Sebastian, that is exactly how I did it after discovering my original method didn't work......
14 years ago
Thank you guys........I was just curious as to how references worked....that's all..........I just used the Mammal class as an example.....
Some while back, I was working w/ arrays, and was trying to call a method that would change the size of an existing array...this method existed in a different class so I had to pass the array(whose size I wanted to change) as a parameter. Inside the method, I defined a temporary array (bigger array), copied all the values from the array that was passed, and then simply pointed the array (formal parameter) to the temp array. But ofcourse, the original array (actual parameter) did not point to the temp array (the bigger array). I figured out another way.....but then I became curious as to if there was a way in java which would allow this.....

By creating aliases, I can certainly change the state of an object, but I can't make one point to a new object (and have the other one automatically point to the new object as well).

Thanks for all your help.
14 years ago
ok guys,

So Mammal human =new Mammal, what if I create another variable that points to the same object as human....So Mammal person; Now I don't want to just simply assign it like person = human, because the person will just copy the reference. Since human refers to some memory space that is storing a reference to this Mammal object, I want person variable to to refer to the same memory space that human is referring to. So basically, I want person to refer to the original reference, not simply store a copy of the reference. Because if human and person both refer to the original reference, by making one of them point to a new object , ex. person = female (female is pointing to some Mammal object), human should also point to the object that female is pointing at, which wouldnt be possible if person was just storing a copy of the reference, in which case person will point to a new object but human will point to the original object.
I hope I am clear enough....
Thanks
14 years ago
Hi,

When you instantiate an object, Mammal human = new Mammal(), the address or reference of the object is stored somewhere in memory which we refer to as human. I don't know how this whole thing works, please someone explain to me in a simple way. So human refers to a block of memory,which contains an address leading to another block of memory which is storing the object???
Thanks
14 years ago

Marcos Stoppa wrote:At Java 5, was added the called autoboxing. With autoboxing you can create a new Wrapper object, with a new value, without manually boxing and unboxing it.



Hey,

It doesn't work, since i is already defined......
14 years ago