Version without JavaScript, read-only: workshops, quizzes and running code are not available here. Full version · Catalogue · Sign in
Sequence
Positive, negative or zero
Core exercise
Write signe(int n) that returns exactly "positif", "negatif" or "nul". The main reads an integer from the keyboard and prints the result: fill in the keyboard input with a number before running.
A workshop goes here: you write and run code in it. It requires JavaScript.
Starting code
Exercices.java
import java.util.Scanner;
public class Exercices {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Entrez un entier : ");
int n = sc.nextInt();
System.out.println(n + " est " + signe(n));
sc.close();
}
public static String signe(int n) {
// TODO : "positif", "negatif" ou "nul"
return "";
}
}
The core exercise is validated in the workshop, which requires JavaScript.
Hint 1
Three cases, hence if / else if / else. Careful: zero is neither positive nor negative.