Viv Richard

Greenhorn
+ Follow
since Jul 08, 2007
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 Viv Richard

Thanks a lot guys. The way I was not right way of thinking. That's why I was having hard time understanding.
I was thinking a-b c-d and 3,2,1,0 as their position in a string. So if my map had to be implemented, the position would have been 0 1 2 3. But the situation here is different abd I realized it. Thanks a lot. I will be back here and talk to you guys again.

Viv
16 years ago
From my book(HeadFirst Java), I was doing an exercise. This exercise was about putting together few pieces of codes which were already provided and also coming up with the provided output. I did the putting together part(which I think is the easiest part, it compiles and gives the required output as well). But I'm having hard time understanding the logic. Here below is the code and expected output:
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
class CodeMagnets
{

public static void main (String[] args){

int z = 3;

if (z >2)
{
System.out.print("a");
}


while (z >0)
{
z = z - 1;
System.out.print("-");



if (z == 1)
{
System.out.print("d");
z = z - 1;

}
if (z == 2)
{
System.out.print("b c");
}





}//end of while
}//end of main
}//end of class

<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

Expected Output:

C:\>java CodeMagnets
a-b c-d

<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

Now my questions are mainly regarding those if statements. HOW or WHY making if statement with z, >, = and numeric value could put those letters in such orderly position?

I can READ the code as which line is doing what such as decrementing, initializing variables, if statement and so on. But I'm having hard time with logic. Help please.
16 years ago
thank you all of you for your support. As soon as I posted my last message, I diagnosed the problem myself and corrected. It's working fine now. And now I logged back on and saw few people already posted help.

Thank all of you once again. I will be back for sure if I have any other problem with code.

Viv
16 years ago
I corrected the "case problem", but now there is new problem after compiling. Could please you tell me what it's trying to say? after typing javac loopy.java in the command console, it's showing message like this:



C:\>javac loopy.java
loopy.java:4: cannot find symbol
symbol : class string
location: class loopy
public static void main (string[] args)
^
1 error

Could you please tell me what exactly it's referring to?
16 years ago
I just started JAVA. I have some programming experiences. I started reading and doing codes from "Headfirst JAVA" book. Rather than just reading the code I have been trying even the examples in the book and trying to compile them. But at this stage of my learning, I have very limited knowledge; especially when black command console shows me an error. I don't understand what type of error it's referring to. The book talks about API reference. But when I go in there, API seems to be some links between thousands of things with little explanation. Besides, when I look at API references, if I don't understand one or 2 links in that API, I don't even get the answer of what I was looking for in that API.

??)Is there any simpler way or any place I can find explanation of the error(s)?

For example: herebelow a small code I copied exactly from the book and wanted to compile it.

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Public class loopy
{

public static void main( string[] args )
{

int x = 1;
System.out.println("Before the Loop");

while (x <4)
{

system.out.println("The value of x is" + x);
x = x + 1;

}

System.out.println("This is after the Loop");

}



}

>>>>>>>>>>>>>>>>>>>>>

after I typed javac loopy.java this was the error in console:

C:\>javac loopy.java
loopy.java:1: class, interface, or enum expected
Public class loopy
^
1 error

>>>>>>>>>>>>>>>>>>>>>>
Now my question is even if book's example doesn't compile, what might happen to the exercises at the end of all chapters?

Help me out reading the error from left to right...
loopy.java:1 class, interface, or enum expected what exactly is it looking for and where can I get the explanation on this?

You might be sensing little frustration in my writing, but it's nothing personal against you. Any type of help would be appreciated.
16 years ago