Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Compiler and Interpreter:

Compiler and Interpreter are the terms related with language transition.

Input Using Scanner Class:


The Scanner class is the latest development in java, which allows the user to read values of
various types. Scanner class is available in the package java.util. You have to input the
package java.util to input data using Scanner class. The process to import java.util package
is:
import java.util.Scanner;

Creating Scanner Object:


After importing java.util package, you have got facility to avail Scanner class and create
object, which can hold a set of values of different types. The syntax to create a Scannerr
object is: Scanner sc = new Scanner(System.in);

if Statement:
You can use if statement to check a specific condition. It performs a course of action if the
condition is true, otherwise the action is ignored.
if the condition is true then both the statements are executed. But if the condition is false,
the control ignores the statements and is passed to the next line of the program.
SYNTAX:
if(condition 1)
{
Statement 1
Statement 2
}

if and only if statement


It is a logical situation where two or more actions are to be performed depending upon the
conditions. When the ‘condition 1’ is true then it perform statement 1. In case ‘condition 1’
is false the control check ‘condition 2’ if it is true then it perform ‘statement 2’ otherwise
goes for checking condition 3 and so on.
SYNTAX:
if(condition 1)
{
Statement 1
}
if(condition 12)
{
Statement 2
}
if(condition 3)
{
Statement 3
}

if-else
You can use if-else statement in a logical situations when either of the 2 actions are to be
performed depending upon certain conditions .it operates one set of statements or other
depending on the given condition is true or false respectively.
SYNTAX:
if(condition 1)
{
Statement 1
}
else
{
Statement 2
}
IF-ELSE IF
It is where more than two actions are to be taken depending upon the conditions with the
keyword ‘else if’. When the ‘condition 1’ is true then it perform statement 1 in case
‘condition 1’ is false then the control enters else's parts and check the condition to further
this statement to our statement 3 is executed depending on condition to is true or false
respectively.
SYNTAX:
if(condition 1)
{
Statement 1
}
else if(condition 2)
{
Statement 2
}
else
{
Statement 3
}

NESTED IF:
When if statement is placed within another if statement it is known as nested if statement
it can be done by using if-else if structure.
SYNTAX:
if(condition 1)
{
if(condition 2)
Statement 1
else
Statement 2
}
else
{
if(condition 3)
Statement 3
else
Statement 4
}

You might also like