Operator in Java Program-3

Operator in Java Program – 3

Operator is very important for all java program languages. Operator can calculate, check, assign, increase and decrease the value of variable. So operator is heart of java program. I give simple example of operator in java program.

ans = (x%5==0 && x%7==0 ) ? “Divided” : “Not Divided”;

In this example ans, x and y are variable;

= (assignment) and > (Relational) and && (logical) are operators.

So we can easily understand the important of operator in java program language. In this blog we will discuss on Logical [ &&, || And ! ] operators.

  1. Logical operator

&&, || and ! are logical operator in java programming languages. These operators help for checking relation of two or more condition. We are familiar with &&, || and ! logical operator in C and Cpp. They work same as C and Cpp. We can also call short circuit operator in java. Let’s see simple logic of logical operator.


&& – Or => Logical Chart


NoStatementAnd [ && ]Or [ || ]
1Condition 1 True , Condition 2 TrueTrueTrue
2Condition 1 True , Condition 2 FalseFalseTrue
3Condition 1 False, Condition 2 TrueFalseTrue
4Condition 1 False, Condition 2 FalseFalseFalse


This is basic chart of logical operator in java program. Let’s see program on logical operator. In this blog we also introduce command line argument. Command line argument uses for assigning run time value in java.


Program on Logical Operator and command line argument:

class op3


public static void main(String args[])


int x = Integer.parseInt(args[0]);

String ans = (x%5==0 && x%7==0) ? “Divided” : “Not Divided”;

System.out.println(x + “ is ” + ans);




If we Insert 20 in X then O/P will be : 20 is Not Divided.

If we insert 35 in X then O/P will be: 35 is Divided.


Video available on YouTube.


If you have problem on this blog, you can directly comment or subscribe on website.



1241total visits,1visits today


Hello, I am Maddy a Java blogger, trainer and developer

Related articles

2 responses to “Operator in Java Program-3”

  1. I am also commenting to let you be aware of what a amazing experience my cousin’s child gained reading through the blog. She realized so many details, most notably what it is like to have an ideal coaching mindset to make other individuals without difficulty fully grasp chosen complicated matters. You actually did more than visitors’ expected results. Many thanks for imparting the interesting, safe, revealing and in addition fun tips about that topic to Mary.