+ 3

what will be the output of this program ? plz help option are in comments

package com.mypack.mytest.course; package com.mypack.online.java; public class Test { public static void main(String[] args) { if(1){ System.out.println("Hello"); } else{ System.out.println("Welcome"); } } }

28th Aug 2019, 4:25 PM
Navneet
Navneet - avatar
18 Respuestas
+ 1
hello @cat Sauce, well you are right if the coding is written in any other language (like c++ or python) but in java, In if statement, as a condition, it will take only take boolean expression or boolean value. So, it gives a compilation error. I have tried it and there is my conclusion. thanks btw for helping. This community is Great!! also, if you try TRUE as the only condition then your answer is right. Like this if(TRUE){ } the above statement will execute
30th Aug 2019, 4:43 PM
Navneet
Navneet - avatar
+ 3
Navneet it will throw you an error coz you haven't mentioned in your if statement i.e what will be 1 ? There must be any variable so that you can compare with or relate with it I hope you understood what I'm saying Enjoy Coding..😁
30th Aug 2019, 12:20 AM
Mayank Kumar
Mayank Kumar - avatar
+ 2
Sharm Farm that would give you a error because you havnt defined its name the code that Navneet gave workes just fine, he was asking why it works
28th Aug 2019, 10:55 PM
Cat Sauce
Cat Sauce - avatar
+ 2
Sharm Farm np dude, everyone has to start somewhere tips to get better: 1. try as much challenges as possible (those challenges that are posted in the same place you can find the courses) maybe 1 every day/two days 2. post as many codes as possible, everytime you learn something cool, code it and publish it (so it becomes harder to forget) 3. challenge yourself, try to make programs you are almost certain you can't make with your current skill set, the harder it is, the more you learn (but dont do a impossible challenge like trying make a superhuman ai) 4. USE GOOGLE, google is the home of a programmer, its his safe place, if you dont understand something or you get a error, try to find the sollution by googeling, it is very important to know what to google when your a programmer good luck fellow coder
28th Aug 2019, 11:20 PM
Cat Sauce
Cat Sauce - avatar
29th Aug 2019, 4:18 PM
Cat Sauce
Cat Sauce - avatar
+ 2
Navneet yeah srry, im not a java guy my main language is c++
30th Aug 2019, 5:14 PM
Cat Sauce
Cat Sauce - avatar
+ 1
1. compile-time error 2. run-time error 3 prints hello 4. prints welcome
28th Aug 2019, 4:27 PM
Navneet
Navneet - avatar
+ 1
hello
28th Aug 2019, 4:29 PM
Cat Sauce
Cat Sauce - avatar
+ 1
1 is the same as "true" and if something is true it will always be executed
28th Aug 2019, 5:11 PM
Cat Sauce
Cat Sauce - avatar
+ 1
hmm. it seem right thanks
28th Aug 2019, 5:13 PM
Navneet
Navneet - avatar
+ 1
youre right.. i just tried it out and it didnt work. im new to this too. shouldnt have posted before i checked 😩
28th Aug 2019, 10:58 PM
Sharm Farm
+ 1
thanks! thats some good advice
28th Aug 2019, 11:57 PM
Sharm Farm
+ 1
Hello
29th Aug 2019, 11:39 AM
THALLAPELLI MOUNIKA
+ 1
error
1st Sep 2019, 1:25 PM
Akash
0
You must do that if(b==1){ System.out.println("hello"); }else{ System.out.println("welcome") }
31st Aug 2019, 11:57 PM
Joaquim João Nsaku Ventura
Joaquim João Nsaku Ventura - avatar
0
1 compile-time error
1st Sep 2019, 12:21 AM
Khelifa Benyoub
Khelifa Benyoub - avatar
0
hi
1st Sep 2019, 10:40 PM
Patrick Erin Parker
Patrick Erin Parker - avatar
0
+2
1st Sep 2019, 11:54 PM
Мишка Кудрик