I've been learning Java for two weeks and I'm stuck on this exercise. This might be a very simple question but I couldn't find the problem yet. I'm trying to test the first method I've written in this algorithme :
1 import java.util.*;
2 public class stationnement {
3 public static void main (String[] args) {
4 int j = jour();
5 System.out.println(j);
6 }
7 public static int jour() {
8 Scanner sc = new Scanner(System.in);
9 System.out.println("Rentrez le jour");
10 int x = sc.nextInt();
11 if (x > 0 && x <=31){return x;}
12 }
13
14 }
When I compile my code I get stationnement.java:12: error: missing return statement }, even though I put the return x after the condition. I tried deleting the if condition and it worked. But I would like to know what's the problem here. Isn't correct to place the condition there?
Thanks a lot for your help :)