Java for Beginners: by Knowledge flow by flow Knowledge
Author:flow, Knowledge [flow, Knowledge]
Language: eng
Format: azw3
Publisher: Knowledge flow
Published: 2015-03-09T04:00:00+00:00
Control Statements
There three types of statements in java.
Selection statements
Iteration statements
Jump statements
Selection statements
It is to manage the flow of programs that is to be executed based on the dynamic conditions which can be only realized during the run time.
It provides flexibility.
If statement- It provides different paths for execution of program.
Syntax
If (condition provided) statement a;
Else
Statement b;
This means if the condition is true, then statement a is executed but if false then statement b is executed.
For example
int a, b;
If (x < y) a=0;
Else
b=0;
Now there is one type of procedure using if statement i.e. nested if statement and it is very common method in programming world.
For example
If (a == 10) {
If (b < 15) i = j;
If (c > 50) p = q;
Else
i = p;
}
Else
i = q;
Now, the second if statement in the parenthesis is associated with else. Another type of procedure is of using if statement is the if-else-if ladder statement.
For example
If (condition)
Statement;
Else if (condition)
Statement;
Else if (condition)
Statement;
.
.
.
.
.
Else
Statement;
Switch statements
It is a multi branched statement.
Syntax
Switch (expression)
{
Case value 1:
Statement
Break;
Case value 2:
Statement
Break;
.
.
.
Case vale n:
Statement
Break;
Default:
Statement;
}
The functioning of the switch statement is compares the given value with all the cases and when the match found the program sequence is executed.
For example
Class sampswitch {
Public static void main (string args [])
{
Switch (i)
{
Case0:
System.out.println (“i is zero.”);
Break;
Case1:
System.out.println(“i is one.”)
Break;
Default:
System.out.println (“i is greater than 4.”)
}
Output
i is zero.
i is one.
i is greater than 4.
i is greater than 4.
Example of nested switch loop program
Switch (countfigures)
{
Case 1:
Switch (targetvalue)
{//nested switch//
Case 0:
System.out.println (“target is zero”;
Break;
Case 1:
System.out.println (“target is one”;
Break;
}
Break;
Case 2: //...
Important features of switch statement are.
Switch statement can only check for equality unlike if.
There cannot be two cases constant in the same switch with identical values.
It is more effective than using the set of nested if statement.
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(8293)
Test-Driven Development with Java by Alan Mellor(6673)
Data Augmentation with Python by Duc Haba(6577)
Principles of Data Fabric by Sonia Mezzetta(6339)
Learn Blender Simulations the Right Way by Stephen Pearson(6226)
Microservices with Spring Boot 3 and Spring Cloud by Magnus Larsson(6098)
Hadoop in Practice by Alex Holmes(5958)
Jquery UI in Action : Master the concepts Of Jquery UI: A Step By Step Approach by ANMOL GOYAL(5806)
RPA Solution Architect's Handbook by Sachin Sahgal(5491)
Big Data Analysis with Python by Ivan Marin(5336)
The Infinite Retina by Robert Scoble Irena Cronin(5192)
Life 3.0: Being Human in the Age of Artificial Intelligence by Tegmark Max(5140)
Pretrain Vision and Large Language Models in Python by Emily Webber(4296)
Infrastructure as Code for Beginners by Russ McKendrick(4057)
Functional Programming in JavaScript by Mantyla Dan(4037)
The Age of Surveillance Capitalism by Shoshana Zuboff(3944)
WordPress Plugin Development Cookbook by Yannick Lefebvre(3771)
Embracing Microservices Design by Ovais Mehboob Ahmed Khan Nabil Siddiqui and Timothy Oleson(3573)
Applied Machine Learning for Healthcare and Life Sciences Using AWS by Ujjwal Ratan(3549)
