//int variable
int n = 10;
if(n==10) {
System.out.println("value is n is : "+n);
}
Answer: value of n is : 10
if(n==9) {
System.out.println("value is n is : "+n);
}
Answer: This statement will not be printed since n does not equal to 9, but 10.
if(!(n==1)){
System.out.println("value is n is not 10. ");
}
Answer: value of n is not 10.
//String variable: equals or not equals , contains or not contains
String day = "Sunday";
if(day.equals("Sunday")){
System.out.println("This is correct day : "+day);
}
Answer: This is correct day : Sunday
if(!(day.equals("Monday"))){
System.out.println("This is not Sunday");
}
Answer: This is not Sunday
if(day.contains("Sun")){
System.out.println("The day is Sunday ");
}
Answer: The day is Sunday
if(!(day.contains("Mon"))){
System.out.println("The day is other than Sunday");
}
Answer: The day is other than Sunday
//boolean variable: true or false
boolean taxable = true;
if(taxable){
System.out.println(" It is taxable. ");
}
Answer: It is taxable.
if(!taxable){
System.out.println(" It is not taxable. ");
}
Answer: Nothing will be printed because taxable is true.
No comments:
Post a Comment