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.

 
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.

 
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

In "PigLatin" a word such as KING is replaced by INGKAYand TROUBLE is replaced by OUBLETRAY and so on. The first vowel of the original word becomes the start of the translation, any proceeding letters being shifted towards the end and followed by AYwords that begin with vowels are left on changed.

 
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 Remove Vowels from a Sentence:

step 1: read String word

step 2: set char array c[]=word. to CharArray()

step 3: create new char array cc[] of size 80

 
by Dinesh Thakur Category: Control Structures

Stack-This class is a predefined class of java.uti1package. A stack represents a group of elements stored in LIFO (Last In Fast Out) order. This means that the element stored as a last element in the stack will be the first element to be removed from the stack.



 
by Dinesh Thakur Category: Control Structures

There will be times when we will want to include more than one statement in the initialization and iteration sections of the For loop. For example, consider the loop in the following program:

 
by Dinesh Thakur Category: Control Structures

In Java, Jump statements are used to unconditionally transfer program control from one point to elsewhere in the program. Jump statements are primarily used to interrupt loop or switch-case instantly. Java supports three jump statements: break, continue, and return.

 
by Dinesh Thakur Category: Control Structures

we have seen how to test whether a given number is prime or not. The program segment given below uses a for loop to test each number in a given range and print it if it is prime.

 
by Dinesh Thakur Category: Control Structures

Nested loop means one loop inside the other. When a loop is written inside the other loop, a condition is essential to maintain: the inner loop will not cross the boundary of the outer loop. That is, the inner loop will begin and end inside the outer loop. We can have any number of loops one inside the other.

 
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.

 
by Dinesh Thakur Category: Control Structures

Length():-This method is a predefined method of String class present in java. Lang package. It is used to determine the length of string and return type of this method is int type.



 

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