Java Tutorial

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.



 
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.

 

Page 8 of 40



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.