Getting an error message in code, but don't know what it means to do

import java.util.*;
import static java.lang.Math.*;
class Mid{
static Scanner console = new Scanner (System.in);
     public static void main(String args[]){
     int i = 0;
     int j = 0;
     int k = 0;
     int mid = 0;
     System.out.print("Enter an integer between 1 and 365: ");
     i = console.nextInt();
     j = console.nextInt();
     k = console.nextInt();
     System.out.println();
     if (i>j && j>k)
     mid = j;
     System.out.println(+ j);
     else if (i<j && j>k)
     mid = max(i, k);
     System.out.println(+ mid);
     else if (i>j && j<k)
     mid = min(i, k);
     System.out.println(+ mid);
     else if (i<j && j<k)
     mid = j;
     System.out.println(+ j);
}keeps telling me 'else' without 'if'
i don't get it, the program is supposed to work such that if i put in 3 distinct numbers, i, j, and k, i can use the program to find out which one is in the middle
Message was edited by:
kribraider414

An if statement without curly brackets only includes the first statement following it, e.g.
if(condition)
    doSomething(); //This one belongs inside the if
    doSomethingElse(); //This one is outside the ifwhereas
if(condition)
    doSomething(); //This one belongs inside the if
    doSomethingElse(); //This one is also inside the if
}So you else if statements are currently floating in the middle of nowhere.

Similar Messages

Maybe you are looking for