• Post Reply Bookmark Topic Watch Topic
  • New Topic

Unexpected error  RSS feed

 
Angel Barnes
Greenhorn
Posts: 4
Chrome Firefox Browser Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This error keeps popping up:

PrintTrianglesA.java:15: error: 'else' without 'if'
                                        else
                                        ^
1 error



Here's the code:

 
Ganesh Patekar
Bartender
Posts: 696
23
Eclipse IDE Hibernate Java jQuery MySQL Database Netbeans IDE Oracle Spring Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On line no 15 you got extra ; herebut even removing that you will get an error because you haven't declared variable k.
 
Henry Wong
author
Sheriff
Posts: 23284
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

The if statement executes a single Java statement (or block), or alternatively, a single statement (or block) specified by else. In your example, you have two Java statements between the if and the else... note that the semicolon right after the if statement is an empty statement.

Henry
 
Angel Barnes
Greenhorn
Posts: 4
Chrome Firefox Browser Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Henry, and Ganesh,
this problem is now solved thanks to you guys.
 
Ganesh Patekar
Bartender
Posts: 696
23
Eclipse IDE Hibernate Java jQuery MySQL Database Netbeans IDE Oracle Spring Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!