Soniya Ahuja

Ranch Hand
+ Follow
since Jul 20, 2008
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 Soniya Ahuja

Micky Kr wrote:Good One...So How Many In Batch You Cover



We cover 1 to 5 students in a batch. Normally, it's a batch of 1-3 students. 5 is the maximum.
12 years ago
@Rob and Jesper: Thanks for the comments guys. I did figure it out that there was some problem once an incorrect datum was entered. To go around it, I was instantiating the Scanner in the try block, but that obviously meant creating a lot of new objects. Now with what you've explained, I can come up with a better solution, probably call next from the catch block. Thanks guys!!
13 years ago

Mohamed Sanaulla wrote:"ten" is not same as entering- 10. nextInt() expects 10 and not "ten".

And as far as the infinite loop is considered- success never becomes true, because there's an exception thrown, catch block tackles it and the loop continues. You can step through a debugger to check the behavior of the program



Hello Mohamed, well thanks for your reply but the problem is that I have entered ten on purpose. Haven't I mentioned that I get an InputMismatchException? Thanks for trying, but I already know the difference between ten and 10. Please read the entire question. Thanks again.
13 years ago


In the code above, if I enter the following input

An InputMismatchException is thrown but it gets thrown infinite times and is followed by 1. I cannot understand that why does int x = sc.nextInt() throw an exception again and again. Is it because something goes wrong with the scanner itself?
13 years ago
You are welcome Nick. Anyway words said by a certain person do not get etched on stone - so you are free to investigate and draw your own conclusions and it's good that you are doing that
13 years ago
Paul Clapton has an apt explanation and I don't see why would someone explain the concept as something that nullifies polymorphism. I don't think that this is a nice term to explain things to a class and more over the listed examples definitely don't add anything to explain the phrase. I guess that he was trying to convey that when you call super.method then the super classes' method gets called and thus at run time overriding does not happen at this particular statement call but then isn't that exactly why we'd want to use super in this scenario? To avoid rewriting logic that may already be present in the super class?

I think it's better that you catch up with your prof and ask him for an explanation... just like paul says
13 years ago
Hi Behrouz,

Just like an array of Strings you can create an array of double

ex double [] hoursOnDays = new double[7];

I have specified the size as 7 for seven days of week.

Now you can simply do something like

hoursOnDays[i] = input.nextDouble();
Just replace all the lines with this one line - the output should be as expected - One line will be printed followed by the console waiting for user input. This will run just 6 times because your for loop starts from 0 and ends when i< 6. If you want it to run 7 times, the condition should be i<7
13 years ago
Onyeabo welcome to Java Ranch! Try to read the error messages - most of the compiler messages are self explanatory

As pointed out by David - readLine is not similar to readline and hence your compiler complains that the method readline cannot be found
13 years ago
The reason why we have a plethora of answers all with different opinions is because the question is not clear. Vonique please be more specific and provide more description about your doubt - especially when there are different ways in which a question can be interpreted, else you can see what happens
13 years ago

Campbell Ritchie wrote:Thank you, Soniya Ahuja


Do you really need to thank me
13 years ago
@Campbell
@Bobby - Welcome
13 years ago
Alright Campbell, sorry I didn't read that part, I guess I should have read it first. At a few places I have put down some code examples. I'll keep them, but I'll make sure that the next time I post, I make sure that I am not divulging too much
13 years ago
Hey David,

I am glad that this worked. However, I suggest you test this for other combination and though this would work fine for smaller arrays, try checking it's performance for larger ones as well.

Good luck
13 years ago
Well, if this the scenario - then try exploring more of Regular Expressions

Here is a crude code that would work for the scenario you have mentioned - try refining the search algorithm and you can explore other classes as well.



Here I am assuming that each * actually stands for one random character and that random character could be between a-z or between A-Z. You can match other options as well - check java.util.regex.Pattern class' API for more details on regex patterns.
13 years ago
Well, if this the scenario - then try exploring more of Regular Expressions

Here is a crude code that would work for the scenario you have mentioned - try refining the search algorithm and you can explore other classes as well.

13 years ago