Andrew Tangen wrote:I can't help you without knowing what the problem is. Your second grouping of code will work fine to read the first/last names after only looking at it for 5 seconds, because its no different from your first batch there. You didn't even need that second class as you said you already had the second file in alpha order.
What was the expected behavior opposed to what actually happened?
Janeice DelVecchio wrote:Mel,
What is the output of your two lines of code?
If you need to assign the int value of the first instance of a variable, you need to use the "=" operator, as fred said -- instead of using the println() method. I would say "the variable k equals the integer result of the "indexOf" method when s1 is the parameter."
The application will only output 0cacoon (not 12cacoon) if you say this:
fred rosenberger wrote:the 'assignment' operator in java is the '=' symbol. you use this to assign a value to a variable.
when you decleare a variable, you must have two things - a type and a name. for example, you could have a 'double' type variable named 'fred'. you would declare it like this:
double fred;
if i then wanted to assign a value to it, i would us the operator mentioned above:
fred = 7.3;
i can also assign the value of one variable to another:
double bob;
bob = fred;
and, i can declare and assign a value in one step:
double george = 17.0;
note that anything that returns the correct type can be used on the right-hand side: a literal (like '12'), another variable (if it's the correct type) or even a method:
george = getValueOfPi();
(assuming there is such a method).
Paul Clapham wrote:
Mel Ram wrote:Usually in math or in programming, when they say k, it refers to any integer... that short program returns and prints an integer of 0.
Yeah, it does, doesn't it? So why did you write that program? It doesn't seem to have much to do with your original post where you said
Assign the index of the first occurrence of the character 'c' in s1 to an int variable k.
Paul Clapham wrote:Well, you didn't use the letter "k" anywhere in that... oh sorry, you just wanted a yes or no answer. Okay. Then the answer is no.
John de Michele wrote:Mel:
This looks like a job for regular expressions.
John.
Ernest Friedman-Hill wrote:Note that after you sort an array, duplicate ints will be adjacent to each other. Does that help you?