Results 1 to 6 of 6
Thread: "else" without "if" error
- 11-26-2010, 09:36 PM #1
Member
- Join Date
- Nov 2010
- Posts
- 40
- Rep Power
- 0
"else" without "if" error
Wow i've googled this and still can't figure out whats the matter? any assistance would be very nice. Thank you.
Java Code:import java.util.Scanner; public class grade { public static void main(String[] args) { Scanner result = new Scanner( System.in ); int numofassi; System.out.println("How many assignments are being graded?"); numofassi = result.nextInt(); if (numofassi == 2) { twograde(); } elseif (numofassi == 3) { threegrade(); } elseif (numofassi == 4) { fourgrade(); } elseif (numofassi == 5) { fivegrade(); } else { System.out.println("Error"); } } public static void twograde(){ Scanner two = new Scanner(System.in); int g1; int g2; System.out.println("Please Enter the first grade... "); g1 = two.nextInt(); System.out.println("Please Enter the second grade... "); g2 = two.nextInt(); int average = (g1 + g2) / 2; System.out.println("The students average is " + average); } public static void threegrade(){ Scanner three = new Scanner(System.in); int g1; int g2; int g3; System.out.println("Please enter the first grade... "); g1 = three.nextInt(); System.out.println("Please enter the second grade... "); g2 = three.nextInt(); System.out.println("Please enter the third grade... "); g3 = three.nextInt(); int average = (g1 + g2 + g3) / 3; System.out.println("The students average is " + average); } public static void fourgrade(){ Scanner four = new Scanner(System.in); int g1; int g2; int g3; int g4; System.out.println("Please enter the first grade... "); g1 = four.nextInt(); System.out.println("Please enter the second grade... "); g2 = four.nextInt(); System.out.println("Please enter the third grade... "); g3 = four.nextInt(); System.out.println("Please enter the fourth grade... "); g4 = four.nextInt(); int average = (g1 + g2 + g3 + g4) / 4; System.out.println("The students average is " + average); } public static void fivegrade(){ Scanner five = new Scanner(System.in); int g1; int g2; int g3; int g4; int g5; System.out.println("Please enter the first grade... "); g1 = five.nextInt(); System.out.println("Please enter the second grade... "); g2 = five.nextInt(); System.out.println("Please enter the third grade... "); g3 = five.nextInt(); System.out.println("Please enter the fourth grade... "); g4 = five.nextInt(); System.out.println("Please enter the fifth grade... "); g5 = five.nextInt(); int average = (g1 + g2 + g3 + g4 + g5) / 5; System.out.println("The students average is " + average); } }
And here is the error from the compiler....
Java Code:sean@Port-nix-system:~/programming/java_source$ javac grade.java grade.java:14: ';' expected } elseif (numofassi == 3) { ^ grade.java:16: ';' expected } elseif (numofassi == 4) { ^ grade.java:18: ';' expected } elseif (numofassi == 5) { ^ grade.java:20: 'else' without 'if' } else ^ 4 errors
- 11-26-2010, 09:37 PM #2
Senior Member
- Join Date
- Oct 2010
- Location
- Germany
- Posts
- 785
- Rep Power
- 12
elseif != else if
-
There is no elseif in Java
- 11-26-2010, 09:38 PM #4
Senior Member
- Join Date
- Feb 2010
- Location
- Ljubljana, Slovenia
- Posts
- 470
- Rep Power
- 12
else if, note the space between.
Ever seen a dog chase its tail? Now that's an infinite loop.
-
Moon, we've been ninja'ed by eRaaaaaaa.
- 11-26-2010, 09:44 PM #6
Member
- Join Date
- Nov 2010
- Posts
- 40
- Rep Power
- 0
Similar Threads
-
connection = DriverManager.getConnection(DATABASE_URL,'"+userid +"','"+password+"');
By renu in forum New To JavaReplies: 3Last Post: 10-12-2010, 05:21 PM -
How to change my form design from "metal" to "nimbus" in Netbeans 6.7.1?
By mlibot in forum New To JavaReplies: 1Last Post: 01-21-2010, 10:20 AM -
Runtime error "Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
By shantimudigonda in forum New To JavaReplies: 1Last Post: 11-20-2009, 08:58 PM -
MoneyOut.println("It took you (whats wrong?>",year,"<WW?) years to repay the loan")
By soc86 in forum New To JavaReplies: 2Last Post: 01-24-2009, 07:56 PM -
the dollar sign "$", prints like any other normal char in java like "a" or "*" ?
By lse123 in forum New To JavaReplies: 1Last Post: 10-20-2008, 08:35 AM
Bookmarks