0% found this document useful (0 votes)
11 views

Java Fundamentals Part-4

Uploaded by

vineelap742
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Java Fundamentals Part-4

Uploaded by

vineelap742
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Java By Venkatesh Mansani Naresh i Technologies

Java Fundamentals
Statements in Java:
There are 3 categories of statements in Java:
1) Selection Statements:
i) if Statement
ii) if else Statement
iii) if else if …. else Statement
iv) Nested if Statement
v) switch Statement
2) Iteration Statements(Loops):
i) while loop
ii) do while loop
iii) for loop
iv) Enhanced for loop
v) Nested loops
3) Jump Statements:
i) break Statement
ii) break LABEL Statement
iii) continue Statement
iv) continue LABEL Statement
v) return Statement

Program to demonstrate if Statement:


class Demo
{
public static void main(String args[])

venkatesh.mansani@yahoo.com Naresh i Technologies


Java By Venkatesh Mansani Naresh i Technologies

{
int a=10;
if(a>0)
System.out.println(“Positive Number”);
}
}

Program to demonstrate if else Statement:


class Demo
{
public static void main(String args[])
{
int a=10;
if(a>0)
System.out.println(“Positive Number”);
else
System.out.println(“Negative Number”);
}
}

Program to demonstrate if else if … else Statement:


class Demo
{
public static void main(String args[])

venkatesh.mansani@yahoo.com Naresh i Technologies


Java By Venkatesh Mansani Naresh i Technologies

{
int a=10;
if(a>0)
System.out.println(“Positive Number”);
else if(a<0)
System.out.println(“Negative Number”);
else
System.out.println(“Zero”);
}
}

Program to demonstrate Nested if Statement:


class Demo
{
public static void main(String args[])
{
int a=10;
if(a>0)
{
if(a%2==0)
{
System.out.println(“Even Number”);
}

venkatesh.mansani@yahoo.com Naresh i Technologies


Java By Venkatesh Mansani Naresh i Technologies

else
{
System.out.println(“Odd Number”);
}
}
else
{
if(a<0)
{
System.out.println(“Negative Number”);
}
else
{
System.out.println(“Zero”);
}
}
}
}

Program to demonstrate switch Statement:


class Demo
{
public static void main(String args[])

venkatesh.mansani@yahoo.com Naresh i Technologies


Java By Venkatesh Mansani Naresh i Technologies

{
int a=10;
switch(a)
{
case 1: System.out.println(“One”);
break;
case 2: System.out.println(“Two”);
break;
default: System.out.println(“Invalid”);
}
}
}

By

Mr. Venkatesh Mansani


Naresh i Technologies
venkatesh.mansani@yahoo.com

venkatesh.mansani@yahoo.com Naresh i Technologies

You might also like