Results 1 to 3 of 3
Thread: else without if error
- 07-16-2011, 02:14 PM #1
Member
- Join Date
- Jul 2011
- Posts
- 4
- Rep Power
- 0
else without if error
The complete code is:
public class LetterCheck2 {
public static void main (String args[]){
char simbol = 'A';
simbol=(char)(128.0*Math.random());
if(simbol >= 'A' && simbol <= 'Z'){
System.out.println("Simbolul reprezinta o litera mare si anume " +simbol);
}
else {
if(simbol >= 'a' && simbol <= 'z'){
System.out.println("Simbolul reprezinta o litera mica si anume "+simbol);
}
}
else {
System.out.println("Simbolul nu reprezinta nici o litera");
}
}
}
The error I receive is:
LetterCheck.java:15 'else without if' else {
Can you tell me where I'm wrong?
Thank you in advance!
- 07-16-2011, 02:37 PM #2
Member
- Join Date
- Jul 2011
- Posts
- 43
- Rep Power
- 0
your are using two else in code convert one of the else to else-if
Java Code:if{ } else if{ } // more else if staements if needed else{ }Java Code:public class LetterCheck2 { public static void main (String args[]){ char simbol = 'A'; simbol=(char)(128.0*Math.random()); if(simbol >= 'A' && simbol <= 'Z'){ System.out.println("Simbolul reprezinta o litera mare si anume " +simbol); } else if(simbol >= 'a' && simbol <= 'z'){ System.out.println("Simbolul reprezinta o litera mica si anume "+simbol); } else { System.out.println("Simbolul nu reprezinta nici o litera"); } } }Last edited by fakepics500; 07-16-2011 at 02:45 PM.
- 07-16-2011, 04:07 PM #3
If you properly format your code aligning the closing } with the opening { you would see if there are mismatched {}sCan you tell me where I'm wrong?
@fakepics500 Why didn't you align your posted code?
Java Code:public class LetterCheck2 { public static void main (String args[]) { char simbol = 'A'; simbol=(char)(128.0*Math.random()); if(simbol >= 'A' && simbol <= 'Z'){ System.out.println("Simbolul reprezinta o litera mare si anume " +simbol); } else { if(simbol >= 'a' && simbol <= 'z'){ System.out.println("Simbolul reprezinta o litera mica si anume "+simbol); } } else { // What if does this else belong to??? System.out.println("Simbolul nu reprezinta nici o litera"); } } // end main() } // end classLast edited by Norm; 07-16-2011 at 04:10 PM.
Similar Threads
-
java out of memory error-heap space error
By elsanthosh in forum NetBeansReplies: 4Last Post: 06-15-2010, 09:31 AM -
> Operator cannot be applied error and return incompatible types error
By corney_16 in forum New To JavaReplies: 1Last Post: 03-10-2010, 01:53 PM -
Thread: Error 500--Internal Server Error java.lang.NullPointerException
By jackdear44 in forum New To JavaReplies: 1Last Post: 12-05-2009, 07:28 AM -
java.lang.Error: Error opening DSound for capture
By NARs in forum NetworkingReplies: 1Last Post: 10-26-2009, 04:38 PM -
Diference Between compiler error Garbage collection and Runtime Error?
By makpandian in forum New To JavaReplies: 3Last Post: 01-23-2009, 08:53 AM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks