Why the ! Symbol cannot or is not used in the system.out.println("") when NOT operator is taking place at the if statement. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why the ! Symbol cannot or is not used in the system.out.println("") when NOT operator is taking place at the if statement.

public class Program { public static void main(String[] args) { int age = 25; if(!(age > 18)) { System.out.println("Too Young"); } else { System.out.println("Welcome"); } } } I am asking the question that, whether we should not use ! Symbol inside println statement as "Welcome!"

12th Aug 2019, 2:39 PM
Dhanush Narayanan R
Dhanush Narayanan R - avatar
5 Answers
+ 1
if the '!' is inside the "" it's treated like a String and not like the not-operator ... so yeah you can do that 😄
12th Aug 2019, 2:57 PM
Anton Böhler
Anton Böhler - avatar
+ 1
they don't cover everything in the tutorial aspecially obvious things ... a String can contain any character, a q, a ! and even a 🙂
12th Aug 2019, 4:24 PM
Anton Böhler
Anton Böhler - avatar
+ 1
Sololearn itself is not clear about that..i think so..anyhow thanks!
12th Aug 2019, 4:41 PM
Dhanush Narayanan R
Dhanush Narayanan R - avatar
0
I don't get your question ,but you can replace '!(age > 18)' with 'age <= 18'
12th Aug 2019, 2:51 PM
Anton Böhler
Anton Böhler - avatar
0
But if u check in the java tutorial topic and in conditions and loops and inside that logical operators and find NOT operator, they've not used ! Symbol inside the println statement. Why is it so
12th Aug 2019, 3:10 PM
Dhanush Narayanan R
Dhanush Narayanan R - avatar