Control Flow
Control flow:
Decision making and it enables your program to conditionally execute different code blocks.
IF
if (price>500){
sout("");}
IF ELSE- Example
package ControFlows;
import java.util.Scanner;
public class IfElse {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the browser you want to exec the test <<CHROME,IE,FIREFOX,SAFERI");
String browser=sc.next();
browser= browser.toUpperCase();
if (browser.equals("CHROME")){
System.out.println("Opening browser "+ browser +" Starting test executation");
} else if (browser.equals("IE")) {
System.out.println("Opening browser "+ browser +" Starting test executation");
}else if (browser.equals("FIREFOX")) {
System.out.println("Opening browser "+ browser +" Starting test executation");
}else if (browser.equals("SAFARI")){
System.out.println("Opening browser "+ browser +" Starting test executation");
}else
System.out.println("Selection is Invalid,please choose other browser");
}
}
import java.util.Scanner;
public class IfElse {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the browser you want to exec the test <<CHROME,IE,FIREFOX,SAFERI");
String browser=sc.next();
browser= browser.toUpperCase();
if (browser.equals("CHROME")){
System.out.println("Opening browser "+ browser +" Starting test executation");
} else if (browser.equals("IE")) {
System.out.println("Opening browser "+ browser +" Starting test executation");
}else if (browser.equals("FIREFOX")) {
System.out.println("Opening browser "+ browser +" Starting test executation");
}else if (browser.equals("SAFARI")){
System.out.println("Opening browser "+ browser +" Starting test executation");
}else
System.out.println("Selection is Invalid,please choose other browser");
}
}
Switch statements
package ControFlows;
import java.util.Scanner;
public class SwitchExample {
SwitchExample(){
System.out.println("Programming starting");
System.out.println("compatable brsers are Chrome,IE,Firefox,Saferi");
}
public static void main(String[] args) {
SwitchExample ss= new SwitchExample();
Scanner execureBrowser= new Scanner(System.in);
String browser=execureBrowser.next();
browser=browser.toUpperCase();
switch (browser){
case "CHROME":
System.out.println("Opening browser of selected Choice");
System.out.println("chromechromechrome");
break;
case "IE":
System.out.println("Opening browser of selected Choice");
System.out.println("IEIEIEIEIE");
break;
case "FIREFOX":
System.out.println("Opening browser of selected Choice");
System.out.println("firefoxfirefoxfirefoxfirefox");
break;
case "SAFARI":
System.out.println("Opening browser of selected Choice");
System.out.println("safarisafarisafarisafari");
break;
default:
System.out.println("Test execution is not configured on other browser");
}
}
}
import java.util.Scanner;
public class SwitchExample {
SwitchExample(){
System.out.println("Programming starting");
System.out.println("compatable brsers are Chrome,IE,Firefox,Saferi");
}
public static void main(String[] args) {
SwitchExample ss= new SwitchExample();
Scanner execureBrowser= new Scanner(System.in);
String browser=execureBrowser.next();
browser=browser.toUpperCase();
switch (browser){
case "CHROME":
System.out.println("Opening browser of selected Choice");
System.out.println("chromechromechrome");
break;
case "IE":
System.out.println("Opening browser of selected Choice");
System.out.println("IEIEIEIEIE");
break;
case "FIREFOX":
System.out.println("Opening browser of selected Choice");
System.out.println("firefoxfirefoxfirefoxfirefox");
break;
case "SAFARI":
System.out.println("Opening browser of selected Choice");
System.out.println("safarisafarisafarisafari");
break;
default:
System.out.println("Test execution is not configured on other browser");
}
}
}
Comments
Post a Comment