1
Java Programming
Statement and loop
2
Control Statement
________________________________________
If Else Statement
In Java, if statement is used for testing the conditions. The condition matches the statement it returns true
else it returns false. There are four types of If statement they are:
i. if statement
ii. if-else statement
iii. if-else-if ladder
iv. nested if statement
if Statement
In Java, if statement is used for testing conditions. It is used for only true condition.
Syntax:
if(condition)
{
//code
}
3
Example:
public class IfDemo1 {
public static void main(String[ ] args)
{
int marks=70;
if(marks > 65)
{
System.out.print("First division");
}
}
}
4
if-else Statement
In Java, the if-else statement is used for testing conditions. It is used for true as well as for false condition.
Syntax:
if(condition)
{
//code for true
}
Else
{
//code for false
}
public class IfElseDemo1 {
public static void main (String[] args)
{
5
int marks=50;
if (marks > 65)
{
System.out.print("First division");
}
else
{
System.out.print("Second division");
}
}
}
6
if-else-if ladder Statement
In Java, the if-else-if ladder statement is used for testing conditions. It is used for testing one condition from multiple
statements.
Syntax:
if(condition1)
{
//code for if condition1 is true
}
else if(condition2)
{
//code for if condition2 is true
}
else if(condition3)
{
//code for if condition3 is true
}
...
else
{
//code for all the false conditions
}
7
Nested if statement
In Java, the Nested if statement is used for testing conditions. In this, one if block is created inside another if block when the
outer block is true then only the inner block is executed.
Syntax:
if(condition)
{
//statement
if(condition)
{
//statement
}
}
8
Example:
public class NestedIfDemo1 {
public static void main(String[] args)
{
int age=25;
int weight=70;
if(age>=18)
{
if(weight>50)
{
System.out.println("You are eligible");
}
}
}
}
9
Nested try block
In Java, there can be multiple try blocks. A try block within another try block is known as nested try block. In a program
when any block of code can cause an error and the entire program can cause another error then try blocks are made
try
{
statements
try
{
Statements
try
{
statements
}
catch (Exception e)
{
}
10
}
catch(Exception e)
{
}
}
catch(Exception e)
{
}
Example
class NestedDemo1
{
public static void main(String args[])
{
try{
11
try{
System.out.println("Divide 39/0");
int b =39/0;
}
catch(ArithmeticException e)
{
System.out.println(e);
} try{
int a[]=new int[8];
a[8]=4;
}
12
catch(ArrayIndexOutOfBoundsException e)
{
System.out.println(e);
}
}
catch(Exception e)
{
System.out.println(e);
}
}
}
13
For Loop
In Java, for loop is used for executing a part of the program again and again. When the number of execution is fixed then it is
suggested to use for loop. In java there are 3 types of for loops, they are as follows:
1. Simple for loop
2. For-each loop
3. labelled for loop
Syntax:
for(initialization; condition; increment/decrement)
{
//statement
}
14
Parameters:
1) Initialization
It is the initial condition which is executed only once at the starting of a loop. It is an optional condition.
2) Condition
It is used to test a condition each time while executing. The execution continues until the condition is false. It is an optional
condition.
3) Statement
It is executed every time until the condition is false.
4) Increment/Decrement
It is used for incrementing and decrementing the value of a variable. It is an optional condition.
15
Example for simple For loop
public class ForDemo1
{
public static void main(String[] args)
{
int n, i;
n=2;
for(i=1;i<=10;i++)
{
System.out.println(n+"*"+i+"="+n*i);
}
}
}
16
Example for Nested for loop
public class ForDemo2
{
public static void main(String[]args)
{
for(int i=1;i<=5;i++)
{
for(int j=1;j<=i;j++)
{
System.out.print("* ");
}
System.out.println();
} }
}
17
for-each Loop
In Java, for each loop is used for traversing array or collection. In this loop, there is no need for increment or decrement
operator.
Syntax:
for(Type var:array)
{
//code for execution
}
Example:
public class ForEachDemo1
{
public static void main(String[] args)
{
Int a[]={20,21,22,23,24};
for(int i:a)
18
{
System.out.println(i);
}
}
}
Labelled For Loop
In Java, Labelled For Loop is used to give label before any for loop. It is very useful for nesting for loop.
Syntax:
labelname :
for(initialization; condition; incr/decr)
{
//code for execution
}
19
Example:
public class LabeledForDemo1
{
public static void main(String[] args)
{
num:
for(int i=1;i<=5;i++)
{
num1:
for(int j=1;j<=5;j++)
{
if(i==2&&j==2)
{
break num;
}
System.out.println(i+" "+j);
}
}
}
}
20
Switch Statement
In Java, the switch statement is used for executing one statement from multiple conditions. it is similar to an if-else-if ladder. In
a switch statement, the expression can be of byte, short, char and int data types. From JDK7 enum, String class and the
Wrapper classes can also be used. Following are some of the rules while using the switch statement:
1. There can be one or N numbers of cases.
2. The values in the case must be unique.
3. Each statement of the case can have a break statement. It is optional.
Syntax:
switch(expression)
{
case value1:
//code for execution;
break; //optional
case value2:
// code for execution
21
break; //optional
......
......
......
Case value n:
// code for execution
break; //optional
default:
code for execution when none of the case is true;
}
22
While Loop
In Java, While loop is a control statement. It is used for iterating a part of the program several times. When the number of
iteration is not fixed then while loop is used.
Syntax:
while(condition)
{
//code for execution
}
Example:
public class WhileDemo1
{
public static void main(String[] args)
{
int i=1;
while(i<=10)
{
System.out.println(i);
i++;
}
}
}
23
Example for infinite while loop
public class WhileDemo2
{
public static void main(String[] args)
{
while(true)
{
System.out.println("infinitive while loop");
}
}
}
24
do-while loop
In Java, the do-while loop is used to execute a part of the program again and again. If the number of iteration is not fixed then
the do-while loop is used. This loop executes at least once because the loop is executed before the condition is checked.
Syntax:
do
{
//code for execution
}while(condition);
Example:
public class DoWhileDemo1
{
public static void main(String[] args)
{
Int i=1;
do {
System.out.println(i);
i++;
}while(i<=10);
}
}
25
Break Statement
In Java, a break statement is used inside a loop. The loop is terminated immediately when a break statement is encountered
and resumes from the next statement.
Syntax:
jump-statement;
break;
Example:
public class BreakDemo1 {
public static void main(String[] args) {
for(int i=1;i<=10;i++){
if(i==8){
break;
}
System.out.println(i);
}
}
}
26
Example using break in do while loop
public class BreakDoWhileDemo1
{
public static void main(String[] args)
{
int i=1;
do
{
if(i==15)
{
i++;
break;
}
System.out.println(i);
i++;
}while(i<=20);
}
}
27
continue Statement
In Java, the Continue statement is used in loops. Continue statement is used to jump to the next iteration of the loop
immediately. It is used with for loop, while loop and do-while loop.
jump-statement;
continue;
Example:
public class ContinueDemo1
{
public static void main(String[] args)
{
for(int i=1; i<=10; i++)
{
if(i==5)
{
continue;
}
System.out.println(i);
} } }
28
Example:
public class ContinueDemo2 {
public static void main(String[] args) {
xy:
for(int i=1;i<=5;i++){
pq:
for(int j=1;j<=5;j++){
if(i==2&&j==2){
continue xy;
}
System.out.println (i+" "+j);
}
} }
}
29
Java return Keyword
Java return keyword is used to complete the execution of a method. The return followed by the appropriate value that is
returned to the caller. This value depends on the method return type like int method always return an integer value.
Points to remember
o It is used to exit from the method.
o It is not allowed to use return keyword in void method.
o The value passed with return keyword must match with return type of the method.
Example
public class ReturnExample1 {
int display()
{
return 10;
}
30
public static void main(String[] args) {
ReturnExample1 e =new ReturnExample1();
System.out.println(e.display());
}
}
Output
10
31
Example
public class ReturnExample2 {
void display ()
{
return null;
}
public static void main (String [] args) {
ReturnExample2 e =new ReturnExample2();
e. display ();
}
}
Output:
Void methods cannot return a value
32
/* Java Program Example - Interchange Two Numbers */
import java.util.Scanner;
public class swap
{
public static void main(String args[])
{
int a, b, temp;
Scanner scan = new Scanner(System.in);
System.out.print("Enter Value of A and B :n");
System.out.print("A = ");
a = scan.nextInt();
System.out.print("B = ");
b = scan.nextInt();
temp = a;
a = b;
b = temp;
System.out.print("Number Interchanged Successfully..!!n");
System.out.print("A = " +a);
System.out.print("nB = " +b);
}
}
33
/* Java Program Example - Convert Fahrenheit to Centigrade */
import java.util.Scanner;
public class fahren
{
public static void main(String args[])
{
float fah;
double cel;
Scanner scan = new Scanner(System.in);
System.out.print("Enter Temperature in Fahrenheit : ");
fah = scan.nextFloat(); //input 68
cel = (fah-32) / 1.8;
System.out.print("Equivalent Temperature in Celsius = " + cel); // 20.0
}
}
34
/* Java Program Example - Print Table of Number */
import java.util.Scanner;
public class table
{
public static void main(String args[])
{
int num, i, tab;
Scanner scan = new Scanner(System.in);
System.out.print("Enter a Number : ");
num = scan.nextInt(); //5
System.out.print("Table of " + num + " isn");
for(i=1; i<=10; i++)
{
tab = num*i;
System.out.print(num + " * " + i + " = " + tab + "n");
}
}
}
35
// creation of table of 2 through command line
import java.io.*;
class table2{
static int sum=0; // static is required
static int t=2,p;
public static void main(String args[])
{
System.out.println(args[0]); // pass the base address i:e args[0]
for(int i=1;i<=Integer.parseInt(args[0]);i++) // convert string args[0] to integer value
{
p=i*t;
System.out.println(i + "*" + t + "=" +p);
}
}
}
// input java table2 10 output is tableof 2 i:e 2 4 6 8 10--------=20
36
/* Java Program Example - Calculate Arithmetic Mean */
import java.util.Scanner;
public class mean
{
public static void main(String args[])
{
int n, i, sum=0, armean;
int arr[] = new int[50];
Scanner scan = new Scanner(System.in);
System.out.print("How many Number you want to Enter ?
");
n = scan.nextInt();
System.out.print("Enter " +n+ " Numbers : ");
for(i=0; i<n; i++)
{
arr[i] = scan.nextInt();
sum = sum + arr[i];
37
}
armean = sum/n;
System.out.print("Arithmetic Mean = " +armean);
}
}
// WAP to create Fibonacci series
import java.util.*;
public class fibo
{
public static void main (String[] args)
{
fibo fs=new fibo();
38
fs.fibonacci();
}
public void fibonacci()
{
int numb1 = 1;
int numb2 = 1;
int temp = 0;
Scanner input=new Scanner(System.in);
System.out.println("How Many Terms? (Up To 45)");
int x=input.nextInt();
x=x-2;
39
System.out.println (numb1);
System.out.println (numb2);
for (int i = 0; i < x; i++)
{
System.out.println(numb1 + numb2 + " ");
temp = numb1;
numb1 = numb2;
numb2 = temp + numb2;
}
}
}
40
// Java Program Example WAP enter character and Check Alphabet or Not
import java.util.Scanner;
public class alphabet
{
public static void main(String args[])
{
char ch;
Scanner scan = new Scanner(System.in);
System.out.print("Enter a Character : ");
ch = scan.next().charAt(0); // enter character x
if((ch>='a' && ch<='z') || (ch>='A' && ch<='Z'))
{
System.out.print(ch + " is an Alphabet");
}
else
{
System.out.print(ch + " is not an Alphabet");
}
}
}
41
/* Java Program Example - Generate Armstrong Numbers */
import java.util.Scanner;
public class armsgen
{
public static void main(String args[])
{
int num1, num2, i, n, rem, temp, count=0;
Scanner scan = new Scanner(System.in);
/* enter the interval (two number) */
System.out.print("Enter the Interval :n");
System.out.print("Enter Starting Number : ");
num1 = scan.nextInt(); //1
System.out.print("Enter Ending Number : ");
num2 = scan.nextInt(); //160
42
for(i=num1+1; i<num2; i++)
{
temp = i;
n = 0;
while(temp != 0)
{
rem = temp%10;
n = n + rem*rem*rem;
temp = temp/10;
}
if(i == n)
{
if(count == 0)
{
43
System.out.print("Armstrong Numbers Between the Given Interval are :n");
}
System.out.print(i + " "); // output 153
count++;
}
}
if(count == 0)
{
System.out.print("Armstrong Number not Found between the Given Interval.");
}
}
}
44
/* Java Program Example - Find Largest of Three Numbers */
import java.util.Scanner;
public class largest
{
public static void main(String args[])
{
int a, b, c, big;
Scanner scan = new Scanner(System.in);
System.out.print("Enter Three Numbers : ");
a = scan.nextInt();
b = scan.nextInt();
c = scan.nextInt();
// let a is the largest
big = a;
if(big<b)
{
45
if(b>c)
{
big = b;
}
else
{
big = c;
}
}
else if(big<c)
{
if(c>b)
{
big = c; }
46
{
big = b;
}
}
else
{
big = a;
}
System.out.print("Largest Number is " +big);
}
}

Loop

  • 1.
  • 2.
    2 Control Statement ________________________________________ If ElseStatement In Java, if statement is used for testing the conditions. The condition matches the statement it returns true else it returns false. There are four types of If statement they are: i. if statement ii. if-else statement iii. if-else-if ladder iv. nested if statement if Statement In Java, if statement is used for testing conditions. It is used for only true condition. Syntax: if(condition) { //code }
  • 3.
    3 Example: public class IfDemo1{ public static void main(String[ ] args) { int marks=70; if(marks > 65) { System.out.print("First division"); } } }
  • 4.
    4 if-else Statement In Java,the if-else statement is used for testing conditions. It is used for true as well as for false condition. Syntax: if(condition) { //code for true } Else { //code for false } public class IfElseDemo1 { public static void main (String[] args) {
  • 5.
    5 int marks=50; if (marks> 65) { System.out.print("First division"); } else { System.out.print("Second division"); } } }
  • 6.
    6 if-else-if ladder Statement InJava, the if-else-if ladder statement is used for testing conditions. It is used for testing one condition from multiple statements. Syntax: if(condition1) { //code for if condition1 is true } else if(condition2) { //code for if condition2 is true } else if(condition3) { //code for if condition3 is true } ... else { //code for all the false conditions }
  • 7.
    7 Nested if statement InJava, the Nested if statement is used for testing conditions. In this, one if block is created inside another if block when the outer block is true then only the inner block is executed. Syntax: if(condition) { //statement if(condition) { //statement } }
  • 8.
    8 Example: public class NestedIfDemo1{ public static void main(String[] args) { int age=25; int weight=70; if(age>=18) { if(weight>50) { System.out.println("You are eligible"); } } } }
  • 9.
    9 Nested try block InJava, there can be multiple try blocks. A try block within another try block is known as nested try block. In a program when any block of code can cause an error and the entire program can cause another error then try blocks are made try { statements try { Statements try { statements } catch (Exception e) { }
  • 10.
    10 } catch(Exception e) { } } catch(Exception e) { } Example classNestedDemo1 { public static void main(String args[]) { try{
  • 11.
    11 try{ System.out.println("Divide 39/0"); int b=39/0; } catch(ArithmeticException e) { System.out.println(e); } try{ int a[]=new int[8]; a[8]=4; }
  • 12.
  • 13.
    13 For Loop In Java,for loop is used for executing a part of the program again and again. When the number of execution is fixed then it is suggested to use for loop. In java there are 3 types of for loops, they are as follows: 1. Simple for loop 2. For-each loop 3. labelled for loop Syntax: for(initialization; condition; increment/decrement) { //statement }
  • 14.
    14 Parameters: 1) Initialization It isthe initial condition which is executed only once at the starting of a loop. It is an optional condition. 2) Condition It is used to test a condition each time while executing. The execution continues until the condition is false. It is an optional condition. 3) Statement It is executed every time until the condition is false. 4) Increment/Decrement It is used for incrementing and decrementing the value of a variable. It is an optional condition.
  • 15.
    15 Example for simpleFor loop public class ForDemo1 { public static void main(String[] args) { int n, i; n=2; for(i=1;i<=10;i++) { System.out.println(n+"*"+i+"="+n*i); } } }
  • 16.
    16 Example for Nestedfor loop public class ForDemo2 { public static void main(String[]args) { for(int i=1;i<=5;i++) { for(int j=1;j<=i;j++) { System.out.print("* "); } System.out.println(); } } }
  • 17.
    17 for-each Loop In Java,for each loop is used for traversing array or collection. In this loop, there is no need for increment or decrement operator. Syntax: for(Type var:array) { //code for execution } Example: public class ForEachDemo1 { public static void main(String[] args) { Int a[]={20,21,22,23,24}; for(int i:a)
  • 18.
    18 { System.out.println(i); } } } Labelled For Loop InJava, Labelled For Loop is used to give label before any for loop. It is very useful for nesting for loop. Syntax: labelname : for(initialization; condition; incr/decr) { //code for execution }
  • 19.
    19 Example: public class LabeledForDemo1 { publicstatic void main(String[] args) { num: for(int i=1;i<=5;i++) { num1: for(int j=1;j<=5;j++) { if(i==2&&j==2) { break num; } System.out.println(i+" "+j); } } } }
  • 20.
    20 Switch Statement In Java,the switch statement is used for executing one statement from multiple conditions. it is similar to an if-else-if ladder. In a switch statement, the expression can be of byte, short, char and int data types. From JDK7 enum, String class and the Wrapper classes can also be used. Following are some of the rules while using the switch statement: 1. There can be one or N numbers of cases. 2. The values in the case must be unique. 3. Each statement of the case can have a break statement. It is optional. Syntax: switch(expression) { case value1: //code for execution; break; //optional case value2: // code for execution
  • 21.
    21 break; //optional ...... ...... ...... Case valuen: // code for execution break; //optional default: code for execution when none of the case is true; }
  • 22.
    22 While Loop In Java,While loop is a control statement. It is used for iterating a part of the program several times. When the number of iteration is not fixed then while loop is used. Syntax: while(condition) { //code for execution } Example: public class WhileDemo1 { public static void main(String[] args) { int i=1; while(i<=10) { System.out.println(i); i++; } } }
  • 23.
    23 Example for infinitewhile loop public class WhileDemo2 { public static void main(String[] args) { while(true) { System.out.println("infinitive while loop"); } } }
  • 24.
    24 do-while loop In Java,the do-while loop is used to execute a part of the program again and again. If the number of iteration is not fixed then the do-while loop is used. This loop executes at least once because the loop is executed before the condition is checked. Syntax: do { //code for execution }while(condition); Example: public class DoWhileDemo1 { public static void main(String[] args) { Int i=1; do { System.out.println(i); i++; }while(i<=10); } }
  • 25.
    25 Break Statement In Java,a break statement is used inside a loop. The loop is terminated immediately when a break statement is encountered and resumes from the next statement. Syntax: jump-statement; break; Example: public class BreakDemo1 { public static void main(String[] args) { for(int i=1;i<=10;i++){ if(i==8){ break; } System.out.println(i); } } }
  • 26.
    26 Example using breakin do while loop public class BreakDoWhileDemo1 { public static void main(String[] args) { int i=1; do { if(i==15) { i++; break; } System.out.println(i); i++; }while(i<=20); } }
  • 27.
    27 continue Statement In Java,the Continue statement is used in loops. Continue statement is used to jump to the next iteration of the loop immediately. It is used with for loop, while loop and do-while loop. jump-statement; continue; Example: public class ContinueDemo1 { public static void main(String[] args) { for(int i=1; i<=10; i++) { if(i==5) { continue; } System.out.println(i); } } }
  • 28.
    28 Example: public class ContinueDemo2{ public static void main(String[] args) { xy: for(int i=1;i<=5;i++){ pq: for(int j=1;j<=5;j++){ if(i==2&&j==2){ continue xy; } System.out.println (i+" "+j); } } } }
  • 29.
    29 Java return Keyword Javareturn keyword is used to complete the execution of a method. The return followed by the appropriate value that is returned to the caller. This value depends on the method return type like int method always return an integer value. Points to remember o It is used to exit from the method. o It is not allowed to use return keyword in void method. o The value passed with return keyword must match with return type of the method. Example public class ReturnExample1 { int display() { return 10; }
  • 30.
    30 public static voidmain(String[] args) { ReturnExample1 e =new ReturnExample1(); System.out.println(e.display()); } } Output 10
  • 31.
    31 Example public class ReturnExample2{ void display () { return null; } public static void main (String [] args) { ReturnExample2 e =new ReturnExample2(); e. display (); } } Output: Void methods cannot return a value
  • 32.
    32 /* Java ProgramExample - Interchange Two Numbers */ import java.util.Scanner; public class swap { public static void main(String args[]) { int a, b, temp; Scanner scan = new Scanner(System.in); System.out.print("Enter Value of A and B :n"); System.out.print("A = "); a = scan.nextInt(); System.out.print("B = "); b = scan.nextInt(); temp = a; a = b; b = temp; System.out.print("Number Interchanged Successfully..!!n"); System.out.print("A = " +a); System.out.print("nB = " +b); } }
  • 33.
    33 /* Java ProgramExample - Convert Fahrenheit to Centigrade */ import java.util.Scanner; public class fahren { public static void main(String args[]) { float fah; double cel; Scanner scan = new Scanner(System.in); System.out.print("Enter Temperature in Fahrenheit : "); fah = scan.nextFloat(); //input 68 cel = (fah-32) / 1.8; System.out.print("Equivalent Temperature in Celsius = " + cel); // 20.0 } }
  • 34.
    34 /* Java ProgramExample - Print Table of Number */ import java.util.Scanner; public class table { public static void main(String args[]) { int num, i, tab; Scanner scan = new Scanner(System.in); System.out.print("Enter a Number : "); num = scan.nextInt(); //5 System.out.print("Table of " + num + " isn"); for(i=1; i<=10; i++) { tab = num*i; System.out.print(num + " * " + i + " = " + tab + "n"); } } }
  • 35.
    35 // creation oftable of 2 through command line import java.io.*; class table2{ static int sum=0; // static is required static int t=2,p; public static void main(String args[]) { System.out.println(args[0]); // pass the base address i:e args[0] for(int i=1;i<=Integer.parseInt(args[0]);i++) // convert string args[0] to integer value { p=i*t; System.out.println(i + "*" + t + "=" +p); } } } // input java table2 10 output is tableof 2 i:e 2 4 6 8 10--------=20
  • 36.
    36 /* Java ProgramExample - Calculate Arithmetic Mean */ import java.util.Scanner; public class mean { public static void main(String args[]) { int n, i, sum=0, armean; int arr[] = new int[50]; Scanner scan = new Scanner(System.in); System.out.print("How many Number you want to Enter ? "); n = scan.nextInt(); System.out.print("Enter " +n+ " Numbers : "); for(i=0; i<n; i++) { arr[i] = scan.nextInt(); sum = sum + arr[i];
  • 37.
    37 } armean = sum/n; System.out.print("ArithmeticMean = " +armean); } } // WAP to create Fibonacci series import java.util.*; public class fibo { public static void main (String[] args) { fibo fs=new fibo();
  • 38.
    38 fs.fibonacci(); } public void fibonacci() { intnumb1 = 1; int numb2 = 1; int temp = 0; Scanner input=new Scanner(System.in); System.out.println("How Many Terms? (Up To 45)"); int x=input.nextInt(); x=x-2;
  • 39.
    39 System.out.println (numb1); System.out.println (numb2); for(int i = 0; i < x; i++) { System.out.println(numb1 + numb2 + " "); temp = numb1; numb1 = numb2; numb2 = temp + numb2; } } }
  • 40.
    40 // Java ProgramExample WAP enter character and Check Alphabet or Not import java.util.Scanner; public class alphabet { public static void main(String args[]) { char ch; Scanner scan = new Scanner(System.in); System.out.print("Enter a Character : "); ch = scan.next().charAt(0); // enter character x if((ch>='a' && ch<='z') || (ch>='A' && ch<='Z')) { System.out.print(ch + " is an Alphabet"); } else { System.out.print(ch + " is not an Alphabet"); } } }
  • 41.
    41 /* Java ProgramExample - Generate Armstrong Numbers */ import java.util.Scanner; public class armsgen { public static void main(String args[]) { int num1, num2, i, n, rem, temp, count=0; Scanner scan = new Scanner(System.in); /* enter the interval (two number) */ System.out.print("Enter the Interval :n"); System.out.print("Enter Starting Number : "); num1 = scan.nextInt(); //1 System.out.print("Enter Ending Number : "); num2 = scan.nextInt(); //160
  • 42.
    42 for(i=num1+1; i<num2; i++) { temp= i; n = 0; while(temp != 0) { rem = temp%10; n = n + rem*rem*rem; temp = temp/10; } if(i == n) { if(count == 0) {
  • 43.
    43 System.out.print("Armstrong Numbers Betweenthe Given Interval are :n"); } System.out.print(i + " "); // output 153 count++; } } if(count == 0) { System.out.print("Armstrong Number not Found between the Given Interval."); } } }
  • 44.
    44 /* Java ProgramExample - Find Largest of Three Numbers */ import java.util.Scanner; public class largest { public static void main(String args[]) { int a, b, c, big; Scanner scan = new Scanner(System.in); System.out.print("Enter Three Numbers : "); a = scan.nextInt(); b = scan.nextInt(); c = scan.nextInt(); // let a is the largest big = a; if(big<b) {
  • 45.
    45 if(b>c) { big = b; } else { big= c; } } else if(big<c) { if(c>b) { big = c; }
  • 46.
    46 { big = b; } } else { big= a; } System.out.print("Largest Number is " +big); } }