Can u please tell me... What's wrong with this program.. | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 7

Can u please tell me... What's wrong with this program..

import java.util.*; class temp{ public static void main(String args[]) {int T; Scanner in= new Scanner(System.in); System.out.println("enter the temperature"); T=in.nextInt(); if(T>=20) { System.out.println("day is cold"); } else if(T>20 && T<=40) { System.out.println("day is normal"); } else(T>40) { System.out.println("day is hot"); } } }

3rd Mar 2018, 8:59 AM
Swati Kumari
Swati Kumari - avatar
11 Respostas
+ 7
You can't do else(condition). you can not test condition with else. Use else if(condition) mistake ---> else(T>40) should be ---> else if(T>40)
3rd Mar 2018, 9:17 AM
Sad
Sad - avatar
+ 6
I know šŸ˜‚ nice to play with you šŸ™šŸ˜
6th Oct 2018, 9:45 AM
Manish Verma
Manish Verma - avatar
+ 5
ya OK
6th Oct 2018, 9:48 AM
Manish Verma
Manish Verma - avatar
+ 3
import java.util.*; class temp { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.println("Enter the temperature"); int T; T = in.nextInt(); if(T<=20){ // pay attention to logic errors Ā  Ā Ā  System.out.println("day is cold"); } else if(T>20 && T<=40){ System.out.println("day is normal"); Ā  Ā  Ā  Ā  } else if (T>40){ Ā  Ā  Ā  Ā Ā  System.out.println("day is hot"); Ā  Ā  Ā  Ā  } } }
3rd Mar 2018, 3:25 PM
Adriel Alves Ferreira Silva
Adriel Alves Ferreira Silva - avatar
+ 3
you cannot compare a condition within in else. use else if instead of else.
6th Mar 2018, 1:05 PM
Manish Verma
Manish Verma - avatar
+ 2
don't use else after elseif statement it should be elseif again
15th Oct 2018, 3:27 PM
Alpesh Jay Gadgilwar
Alpesh Jay Gadgilwar - avatar
+ 1
I think: if(T<=20){ .....}
6th Mar 2018, 7:35 PM
Fatemeh. R
Fatemeh. R - avatar
+ 1
challenge limited stop me at sololearn only with your
6th Oct 2018, 9:44 AM
Umesh kumar mahur
Umesh kumar mahur - avatar
+ 1
tomorrow again play okkk
6th Oct 2018, 9:46 AM
Umesh kumar mahur
Umesh kumar mahur - avatar
0
You can not assign a value to else, it doesnt exists else (condition)
14th Oct 2018, 11:18 PM
Gabi Hernandez
Gabi Hernandez - avatar
- 3
Abe BC else if k bad else nai aata else if hi aata
10th Mar 2018, 1:38 PM
Alpesh Jay Gadgilwar
Alpesh Jay Gadgilwar - avatar