Computer Science, asked by aditidwi7, 7 months ago

write a program in java to read the temperature in celcious and display a suitable message according to the temperature stated below:
temp<0 ---> freezing weather
21-30 --->normal weather
31-40 --->hot weather
>40 --->very hot weather

Answers

Answered by Anonymous
2

import java.util.Scanner;

class temp{

public static void main(String[] args){

 Print("Enter temperature in celcius: \n");

 Scanner getInput = new Scanner(System.in);

 int temperature = getInput.nextInt();

 if(temperature <= 0)

  Print("Freezing Weather");

 else if(temperature >= 21 && temperature <= 30)

  Print("Normal Weather");

 else if(temperature >= 31 && temperature <= 40)

  Print("Hot Weather");

 else if(temperature > 40)

  Print("Very Hot Weather");

 else

  Print("Cold Weather");

 getInput.close();

}

public static void Print(Object _object_){

 System.out.print(_object_);

}

}

Answered by anindyaadhikari13
5

Question:-

Write a program in java to read the temperature in celcius and display a suitable message according to the temperature stated below:

<0 >>>>> freezing weather

21-30 >>>>> normal weather

31-40 >>>>> hot weather

>40 >>>>> very hot weather

Code:-

import java.util.*;

class Temperature

{

public static void main(String args[])

{

Scanner sc = new Scanner(System.in);

System.out.print("Enter the temperature: ");

int temp=sc.nextInt();

String s="";

if(temp<0)

s="Freezing ";

else if(temp>=21&&temp<=30)

s="Normal ";

else if(temp>=31&&temp<=40)

s="Hot ";

else if(temp>40)

s="Very hot ";

System.out.println(s+ "weather.");

}

}

Similar questions