Temperature Classification in Java

Classify temperature as cold, moderate, or hot using conditions.

BeginnerModule 2: Conditional ProgramsExample 18 of 20
temperature-classification.java
1import java.util.Scanner;
2
3public class Main {
4 public static void main(String[] args) {
5 Scanner sc = new Scanner(System.in);
6
7 System.out.print("Enter temperature in Celsius: ");
8 double temp = sc.nextDouble();
9
10 if (temp < 10) {
11 System.out.println("Cold");
12 } else if (temp <= 30) {
13 System.out.println("Moderate");
14 } else {
15 System.out.println("Hot");
16 }
17
18 sc.close();
19 }
20}

Output

Enter temperature in Celsius: 35
Hot

What's going on

We define simple ranges: below 10 as cold, 10–30 as moderate, above 30 as hot.