## Nested If in Java Example

by Dinesh Thakur Category: Control Structures

When we have if or if else statement within another if construct or else construct, we call it nested if.

## Do-while Loop in Java, do while syntax Java Example

by Dinesh Thakur Category: Control Structures

The do loop enables us to repeatedly execute a block of code until a boolean expression evaluates to false. It is almost identical to the while loop with the difference that here the logical expression is evaluated at the bottom of the loop rather than the top. This means that the contents of the loop will execute at least once.

## Armstrong Number in Java Example

by Dinesh Thakur Category: Control Structures

Algorithm for Armstrong Number:

step 1:Set s=0

step 3: Set b=num

step 4: Repeat through step-7 while num greater than 0

step 5: r=num%10

step 6: s=s+(r*r*r)

## Enter 10 Number and Print the Number of Positive, Negative and Zeros Number

by Dinesh Thakur Category: Control Structures

In this example we use BufferedReader class for Reading text from a character-input stream. After Enter any 5 Number we check if number ==0 then is zero if number greater than 0 then it is positive other wise negative.

## Math.random() in Java Example

by Dinesh Thakur Category: Control Structures

The Random class provides a template for the creation of random number generators. The Math.random() method provides a static function for the generation of random double values.

Two constructors are provided for creating Random objects. The default constructor initializes the seed of the random number generator using the current system time. The other constructor allows the seed to be set to an initial long value.

## How Many Digits Are Present in the Number - Java Example

by Dinesh Thakur Category: Control Structures

Algorithm for Digits Are Present in the Number:

step 1: Set c=0

step 3: Repeat through step-5 while num greater than 0

step 4: c=c+1

## Swap Two Variables Using XOR Operator Using Java Example

by Dinesh Thakur Category: Control Structures

Algorithm for Swap Two Variables Using XOR Operator:

step 2: a=a^b

step 3: b=b^a

step 4: a=a^b

step 5: Print a,b

step 6: Exit

## currentTimeMillis() Java Example

by Dinesh Thakur Category: Control Structures

The currentTimeMillis() method returns the current time in milliseconds since 00:00:00,January I, 1970.This method is used to know the time interval a process or job takes to perform. We record the time before and after the operation and the difference of two timings tells us the total time the operation took.

## Program To Show Importance of Continue Statement? Java Example

by Dinesh Thakur Category: Control Structures

In this example, the continue statement is placed in the body of inner for loop. While executing inner for loop, if the condition (m==n) evaluates to true then the continue statement is executed and the remaining statement for displaying values of m and n is skipped and control is transferred to the increment expression (n++) of inner for loop. This increments the value of n by 1 and test condition (n<=2) is evaluated again for this incremented value of n. This process continues. We have used continue statement in this program so that the same value of m and n should not be displayed.

## While Loop in Java Example

by Dinesh Thakur Category: Control Structures

The while loop is a construct that repeatedly executes a block of code as long as a boolean condition remains true. The logical expression in while loop is evaluated first. If the logical expression evaluates to false, the body of while loop will not execute even once. If the logical expression in while evaluates to true, the statements in the body of while loop are executed. After executing the body, control jumps again at the top to recheck whether the boolean expression is still true or not. The body of the loop will continue to execute until the expression evaluates to false. When the logical expression becomes false, control continues the execution with the statements following while loop.

## Counting the Number of Non Blank Characters in a String | Java Example

by Dinesh Thakur Category: Control Structures

## Print the table of an input number up till 10 times in Java Example

by Dinesh Thakur Category: Control Structures

## Print n Sequence Numbers in Java Example

by Dinesh Thakur Category: Control Structures

## Java - Number of Times a Word has Been Mentioned | Java Example

by Dinesh Thakur Category: Control Structures

Algorithm for Number of Times a Word has Been Mentioned :

step 3: set len=w1.length()
step 4: set result=0

## Triangle of any size in Java Example

by Dinesh Thakur Category: Control Structures

Algorithm for Triangle of any size:

step 1: set i=0,j=0,row=0,osc=0,var=0

step 3: if row greater than 0 then execute following codes otherwise goto

step-33

step 4: osc=row-l

step 5: set isc= 1

## For Loop | Java Examples

by Dinesh Thakur Category: Control Structures

The for loop enables code to execute repeatedly until a boolean expression evaluates to false.

## Date Format Example in Java

by Dinesh Thakur Category: Control Structures

We can change the format of the date in two steps: First, we create a formatter with the getDateInstance method. Then, we invoke the format method, which returns a String containing the formatted date.

## Print System Date and Time in Java Example

by Dinesh Thakur Category: Control Structures

The Calendar class is an abstract class used to convert dates. We can use this class to convert a Date object to fields, such as YEAR, MONTH, HOUR, and so on. We can also use these fields to update a Date object.

## Java console io Example

by Dinesh Thakur Category: Control Structures

Java.io.Console class is a new class in Java 6 that may be used for reading text from character based console device. The data can be read from the console device provided it is associated with the Java Virtual Machine (JVM).

## Swap Variables in a Different Way Without Using Third Variables

by Dinesh Thakur Category: Control Structures

Algorithm for Swap Variables in a Different Way:

step 2: a=(a+b)-(b=a)

step 3: Print a,b

step 4: Exit

Page 3 of 4

Dinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.

Related Articles