Results 1 to 6 of 6
  1. #1
    seanfmglobal is offline Member
    Join Date
    Nov 2010
    Posts
    40
    Rep Power
    0

    Default "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

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    6

    Default

    elseif != else if

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    There is no elseif in Java

  4. #4
    m00nchile is offline Senior Member
    Join Date
    Feb 2010
    Location
    Ljubljana, Slovenia
    Posts
    470
    Rep Power
    5

    Default

    else if, note the space between.
    Ever seen a dog chase its tail? Now that's an infinite loop.

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Moon, we've been ninja'ed by eRaaaaaaa.

  6. #6
    seanfmglobal is offline Member
    Join Date
    Nov 2010
    Posts
    40
    Rep Power
    0

Similar Threads

  1. Replies: 3
    Last Post: 10-12-2010, 05:21 PM
  2. Replies: 1
    Last Post: 01-21-2010, 10:20 AM
  3. Replies: 1
    Last Post: 11-20-2009, 08:58 PM
  4. Replies: 2
    Last Post: 01-24-2009, 07:56 PM
  5. Replies: 1
    Last Post: 10-20-2008, 08:35 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •