2. Conditional statements
• Basic 2 ways of conditional statements in java
1. If statements
a. if-else
b. if -else if- else
2. Switch Statements
3. If-else statements
• Syntax
if (condition)
{
// runs if condition will be
true
}
else
{
// runs when condition will be
false
}
• Example
4. If else if statement
• Syntax
if (condition)
{
// runs if condition will be true
}
else if(condition)
{ // runs if this condition will be true
}
else
{
// runs when condition will be false
}
12. Accessor Methods
• Methods used to obtain information about an object are known
as accessor methods.
• For example
1. length of string
2. concatenating two strings
13. Finding length of string
• It returns number of character
contained in the string
• How to use
String name=“maria”;
Int length= name.length();
Concatenating two strings
• It returns a new string which
contains string 1 and staring 2
added to each other at the end
• How to use
string1.concat(string2);
Commonly; we use ‘+’ operator to
combine two strings
String string1=“maria”;
System.out.println(“My name
is”+string1);