Java Question

Why am I getting that error when typing "else if"?

So I'm new in java and I just started learning and while making a very simple program to determine whether the current temperature is hot, warm or cold.
It's all OK, but when I type "else if", I get a bug and I'd like to know how to fix it and the most important thing: why am I getting this error? So I don't repeat it again. I have already searched for an answer to my question but I have found nothing, so that's why I'm asking here. Here you can see the error I get:

package com.marin.src;

import java.util.Scanner;

public class MainClass {

public static void main(String[] args){

double temp;
Scanner s = new Scanner(;

System.out.println("Introduce una temperatura: "); //That only means "enter a temperature"
temp = s.nextDouble();

if(temp > 30){
System.out.println("Hace calor."); //That only means "it's hot"
System.out.println("Hace frío."); //That only means "it's cold"
else if (temp > 25){
System.out.println("La temperatura es normal."); //that only means "it's warm"


Answer Source

Because you are trying to write else if after else statement. Your else statement should be written as last condition. It's the case that executes at final if any of the above cases was not satisfied.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download