Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Rules Round Up - Doubt - Errada?

 
raja kanak
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please check question number #154, it says
(#154) Assuming all variables are declared and initialized properly, will this compile?
for(i=1;k<5;j++){};
Options:
yes
No

I select "No" because of the semicolon at the end. But the applet says the answer is "Yes".

I guess that semicolon should be removed from the question. Am i right?
 
Sampath Satha
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
where java ends!
 
Sampath Satha
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
semicolon endsline after the empty braces
 
Henry Wong
author
Marshal
Pie
Posts: 20997
76
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Assuming all variables are declared and initialized properly, will this compile?


Well, if you put this line of code, along with all variables, declared and initialized properly, does it compile?

It takes less than a minute to actually try it out.

Henry
 
raja kanak
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Henry Wong:


Well, if you put this line of code, along with all variables, declared and initialized properly, does it compile?

It takes less than a minute to actually try it out.

Henry


This is called communication gap :roll:
I want to mention the typo in Rules Roundup. thats it.
With semicolon - error
Without semicolon - no problem.
Once again I want to mention the typo in Rules Roundup. thats it
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But I don't think it is a typo. One of the points of the question is that it's possible to have an extra ';' in code, and it doesn't cause any error. In this case it doesn't create any problem at all - it's just an empty statement, legal just about anywhere.
 
Henry Wong
author
Marshal
Pie
Posts: 20997
76
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by raja kanak:

This is called communication gap :roll:
I want to mention the typo in Rules Roundup. thats it.
With semicolon - error
Without semicolon - no problem.
Once again I want to mention the typo in Rules Roundup. thats it


This code will compile with (or without) the semicolon.

Why do you think that the semicolon will cause an error?

Henry
 
raja kanak
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

This code will compile with (or without) the semicolon.

Why do you think that the semicolon will cause an error?

Sorry for my mistake. You are right. The code compiles with (or without) semicolon.

But in case of enum it is mentioned about semicolon. I don't find any mention about semicolon regarding if statement in K&B book. That's why I confused.
 
Javier Sanchez Cerrillo
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey raja kanak


Will this compile:?

public class Javier {
public static void main(String[] args) {
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
System.out.println("Hello World");;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;
}

}

I think you should better try the code by yourself before posting or reporting errata.
 
raja kanak
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I really feel shy. I am very sorry. I will definitely take extra care before posting any thing in future.

The code you mentioned compiled. that is terrific.

Anybody please conclude this topic by giving the clear rules regarding semicolon.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic