by Dinesh Thakur Category: Control Structures

Algorithm for Number of Times a Word has Been Mentioned :

step 1: read String w
step 2: read String w1
step 3: set len=w1.length()
step 4: set result=0

 
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

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

 
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.

 
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.

 
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 Swap Variables in a Different Way:

step 1: Read a, b

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

step 3: Print a,b

step 4: Exit

 
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

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

Finalizer methods are almost the opposite of constructor methods. A constructor method is used to initialize an object, while finalizer methods are called just before the object is garbage-collected and its memory reclaimed. The syntax of the finalizer method is simply finalize(). The Object class defines a default finalizer method. To create a finalizer method, override the finalize() method using the following signature:

 
by Dinesh Thakur Category: Control Structures

Currently the definition of Greatest Common Divisor (GDC) can be formalized as well:

Let a, b and c nonzero integers, we say that c is a common divisor of a and b to c divides (write c | a) and c divides b (c | b). We call D (a, b) the set of all common divisors of a and b.

The code snippet below shows how to calculate the GDC two reported numbers:

 

Page 4 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