Thursday, March 31, 2022

Java Program Operators PART - 3

 package selenium;

public class Operators {

public static void main(String[] args) {

//Conditional Operator - Use of Ternary operator

int age =20;

String res=(age >=18) ? "Eligible to vote": "Not eligible to vote";

System.out.println(res);

int a = 10;

int res1=++a; //pre increment   11 //first increases value of a then assignment happens

System.out.println(res1); //10

System.out.println(a);

boolean x=true;

boolean y=false;

System.out.println(x && y); // false if both values are true will return true if not false.&& - AND operator

System.out.println(x || y); // true if either one is true give true.|| - OR operator

System.out.println(!x); //false

System.out.println(!y); //true

}

}


No comments:

Post a Comment