by Dinesh Thakur Category: Control Structures

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

 
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.

 
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.

 
by Dinesh Thakur Category: Control Structures

The switch statement is a multi-way decision making statement which selects one of several alternatives based on the value of an integer variable or expression. The switch statement is mainly used to replace multiple if-else-if statement. The if-else-if statement causes performance degradation as several conditions need to be evaluated before a particular condition is satisfied.

 
by Dinesh Thakur Category: Control Structures

When there is requirement of several branching i.e. if we need several if statements, it is better to use switch statement. In other words, switch is a variation of if statement which performs multiway branching.

 
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.

 
by Dinesh Thakur Category: Control Structures

A common programming construct that is based upon a sequence of nested ifs is the if-else-if ladder.

 
by Dinesh Thakur Category: Control Structures

This statement helps in choosing one set of statement out of two sets depending on the validity of the logical expression included. It is also known as conditional branch statement as it is used to route program execution through two different paths.

 
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).

 
by Dinesh Thakur Category: Control Structures

Algorithm for Java Sum of Digits :

 

step 1: Set sum=0

step 2: Read num

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

step 4: temp=num % 10

step 5: sum=sum+temp

 
by Dinesh Thakur Category: Control Structures

Algorithm for Digits Are Present in the Number:

step 1: Set c=0

step 2: Read num

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

step 4: c=c+1

 
by Dinesh Thakur Category: Control Structures

Algorithm for Check Number is Binary or Not:

step 1: Set r=0,c=0

step 2: Read num

step 3: Set b=num

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

 
by Dinesh Thakur Category: Control Structures

Algorithm for Highest Prime Number:

step 1: Read num

step 2: Set i== 1

step 3: Initialize j==2

step 4: Repeat through step-7 while j less than or equals to num

step 5: If j equals to num then Set i==num and goto 8

step 6: If (num mod)) equals to 0 then num==num-1

 
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 2: read row

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

 
by Dinesh Thakur Category: Control Structures

Algorithm for Right Angled Triangle:

 

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

step 2: Read row

step 3: Move to new line

step4: If (row>O) then execute following steps else goto step-23

step 5: Initialize isc=0

step 6: Print “*”

step 7: Initialize i=2

 
by Dinesh Thakur Category: Control Structures

Algorithm for Floyd Triangle:

step 1: Set a= 1

step 2: Read row

step 3: Initialize i=0

step 4: Repeat through step-12 until i less than row

step 5: Initialize j=0

step 6: Repeat through step-10 until j less than or equals to i

step 7: Print a

 

Page 2 of 4



About Dinesh Thakur

Dinesh ThakurDinesh 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