+ 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"); } } }
18 ответов
+ 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
+ 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..😁
+ 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
+ 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
+ 2
+ 2
Navneet yeah srry, im not a java guy
my main language is c++
+ 1
1. compile-time error
2. run-time error
3 prints hello
4. prints welcome
+ 1
hello
+ 1
1 is the same as "true" and if something is true it will always be executed
+ 1
hmm. it seem right thanks
+ 1
youre right.. i just tried it out and it didnt work. im new to this too. shouldnt have posted before i checked 😩
+ 1
thanks! thats some good advice
+ 1
Hello
+ 1
error
0
You must do that
if(b==1){
System.out.println("hello");
}else{
System.out.println("welcome")
}
0
1 compile-time error
0
hi
0
+2