Subhash Sriram

Greenhorn
+ Follow
since Nov 10, 2003
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Subhash Sriram

Thank you both very much for the info.
19 years ago
Hi,

I have the following code given to me by an instructor:



Everytime I try to compile it, I get an error saying it is expecting a class or interface.

The name of the file is Language.java and I am compiling using J2SDK 1.4.2_06 and I also tried 1.4.2_09.

Is there a reason I am getting this? Do I need to upgrade my SDK or something?

Thank you in advance.
19 years ago

Originally posted by Lasse Koskela:
By the way, I recently wrote three slightly different implementations of the Fibonacci sequence for my article in the April edition of JavaRanch Journal. Especially "FibonacciFloatImpl.java" might be of interest to you (this approach was new to me before I started looking at what kind of solutions for the Fibonacci sequence exist).


Lasse,
Thank you for that link as well as to help me with the problem I am having. I am also using the formula you used in "FibonacciFloatImpl.java" by using the time it takes the computer to calculate that value vs. the time it takes to go through the algorithm, my whole program basically deals with algorithm complexity.
Also, I noticed something in your code, which I stupidly didnt do, which was define a variable called SQRT5, and I used Math.sqrt(5.0) every time it appeared in the formula. I am guessing that if I only define it once, it should reduce the time?
Thanks again for all the help.
20 years ago
Thanks to everyone for the replies. I was told by my instructor that any programming language I use should have a method to do that, but I guess he was wrong.
I am writing two separate programs to get the n-th fibonacci #, one program works recursively, the other iteratively. We are analyzing both algorithms by finding out how much time it takes to find n. I know that the iterative is faster, but he wants a precise value.
According to him, you should not have to write anything to do this, but like I said, he must have been wrong.
Thanks again for the help.
20 years ago
Hi,
Can anyone tell me what function in Java will display the time it takes to execute a procedure of a program, and maybe a link or a brief description of how it works?
Thanks in advance.
20 years ago
Hi,
Thank you all for the replies...
I think I have a fairly ok idea of what to do, except for one thing.
I am reading in a file one character (byte) at a time, and I need to compare each byte to the tab character to see if there is a tab, and then replace with either the default number of spaces or the user specified number of spaces, but I have no idea how to compare the two!
BTW, if it helps, the assignment is shown here:
http://www.cs.uwf.edu/~lwhite/course_pages/java-assignments/java11.htm
Thanks again.
[ November 26, 2003: Message edited by: Subhash Sriram ]
21 years ago
Well, I have noticed a few problems with it right off the bat...I guess I am going back to the drawing board...
If anyone can give me some advice on how to tackle this problem, I would really appreciate it.
21 years ago
Hi,
Thank you for the reply..I modified the processTest function to the following. I found an article on how to do replacements using REGEX, but not when the INPUT is a file, that is what is really confusing me..
Below is the modified function:

And, this is the error that I am getting when running the file.
C:\cis3020\temp>java Homework -5 tester.java
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String ind
ex out of range: -1
at java.lang.String.substring(Unknown Source)
at java.lang.String.subSequence(Unknown Source)
at java.util.regex.Matcher.getSubSequence(Unknown Source)
at java.util.regex.Matcher.appendReplacement(Unknown Source)
at Homework.processTest(Homework.java:90)
at Homework.main(Homework.java:52)
Also, I am not sure how to write the modified line back to the file. We are suppose to have a renameTo function which saves the inFile as a temp file, and then when the changes are made, it renames it back to the same as the input file...Would that have to be done first?
Thanks again
21 years ago
Hi,
I could REALLY use some help here..I have a program that is suppose to take in an input file, along with command line arguments, could be there, doesnt have to. The main function of the program is to check the input file for "tabs", and change all tabs to 3 spaces by default, or if the user specifies another amount, between 1 & 9, it is suppose to change it to that. Also, an optional [-d] option will take off all ^M's from the file (the result of windows --> unix ftp)...
I am using REGEX to check for a pattern, but I am lost as what to do when it finds a pattern, am also getting a couple of errors..Any help would be greatly appreciated.
Here is my code so far:

Thanks in advance.
21 years ago
Hi,
No, I did not know about that package, but I am reading about it now!
Sorry I have not replied anything until now. If I have any other questions, I will post them here.
Thanks again.
21 years ago
Hi,
I am trying to write a program that will take in a file, and replace any tabs in the file by a user-defined #of spaces. I know how to take in the file as input, but I am really lost on how Java would check to see if it is a tab, and if it is, replace the tab with a set amount of spaces, and if the user doesnt put in a number of spaces, it defaults to three...
Any help would be greatly appreciated, I am totally lost!
Thanks
21 years ago
Hi,
I am doing a Java program where users will be able to create pie charts, and I get to design the user interface. I havent got into any of those aspects yet, but am working on a way to just draw a portion of a circle based on what the user enters.
On this first file, I have the class PieChart defining the chart, and what I am wanting to do is take the angle (theta) the user enters in, change it to radians, and then draw that curve in a particular color. I am having trouble with just drawing the curve.
Here is the code I have right now for the class:

I understand there is no for loop in there now, but I am not sure how the best way to do it is.
And, here is my tester program. Instead of taking in user input on this one, just giving a default value.

Any help would be greatly appreciated. Thanks in advance!
The problem is it will not print anything, not even a line between the two points
[ November 10, 2003: Message edited by: Subhash Sriram ]
21 years ago