1. Decision-making in java
- There are two types of decision-making statements in Java. One is very commonly used which is the If statement and you will find it almost in every piece of code. The second is the Switch statement.
various forms of if...else statements in Java:-
if statement
if...else statement
if...else if...else statement
if statement :
Example
package selenium;
public class Java_practise {
public static void main(String[] args) {
String sDay = "Sunday";
int iDay = 7;
if(sDay.equals("Sunday")){
System.out.println("Today is Sunday");
}
if(iDay==7){
System.out.println("Today is Sunday"); }
}
}
if...else statement :
Example
package selenium;
public class Java_practise {
public static void main(String[] args) {
String sDay = "Saturday";
int iDay = 6;
if(sDay.equals("Sunday")){
System.out.println("Today is Sunday");
}else{
System.out.println("Today is not Sunday");
}
if(iDay==7){
System.out.println("Today is Sunday");
}else{
System.out.println("Today is not Sunday");
}
}
}
if...else if...else statement
Example
package selenium;
public class Java_practise {
public static void main(String[] args) {
String sDay = "Monday";
int iDay = 1;
if(sDay.equals("Sunday")){
System.out.println("Today is Sunday");
}else if(sDay.equals("Saturday")){
System.out.println("Today is not Saturday");
}else{
System.out.println("Today is a Weekday");
}
if(iDay==7){
System.out.println("Today is Sunday");
}else if(iDay==6){
System.out.println("Today is Saturday");
}else{
System.out.println("Today is a Weekday");
}
}
}
No comments:
Post a Comment