Found 7442 Articles for Java

Fibonacci series program in Java without using recursion.

Syed Javed
Updated on 18-Jun-2020 06:48:02

4K+ Views

Following is the required program.ExampleLive Demopublic class Tester {    public static void main(String args[]) {        int n1 = 0, n2 = 1, n3, i, max = 5;        System.out.print(n1 + " " + n2);        for (i = 2; i < max; ++i) {           n3 = n1 + n2;           System.out.print(" " + n3);           n1 = n2;           n2 = n3;        }     }  }Output0 1 1 2 3

Fibonacci series program in Java without using recursion.

Syed Javed
Updated on 18-Jun-2020 06:48:02

4K+ Views

Following is the required program.ExampleLive Demopublic class Tester {    public static void main(String args[]) {        int n1 = 0, n2 = 1, n3, i, max = 5;        System.out.print(n1 + " " + n2);        for (i = 2; i < max; ++i) {           n3 = n1 + n2;           System.out.print(" " + n3);           n1 = n2;           n2 = n3;        }     }  }Output0 1 1 2 3

break, continue and label in Java loop

Alshifa Hasnain
Updated on 20-Mar-2025 18:18:14

4K+ Views

In this article. we will learn about break, continue, and label in Java loop. There are cases when you would want to manage the flow of your loop, that is, skip some iterations or terminate the loop altogether. This is where break, continue, and label statements are used. Break Statement A break statement interrupts the normal execution of a loop and causes it to exit before being completed. The loop will terminate and the flow of control will transfer to the next statement immediately following the loop, when the break function is called. It can be used in any loop statement, ... Read More

break, continue and label in Java loop

Alshifa Hasnain
Updated on 20-Mar-2025 18:18:14

4K+ Views

In this article. we will learn about break, continue, and label in Java loop. There are cases when you would want to manage the flow of your loop, that is, skip some iterations or terminate the loop altogether. This is where break, continue, and label statements are used. Break Statement A break statement interrupts the normal execution of a loop and causes it to exit before being completed. The loop will terminate and the flow of control will transfer to the next statement immediately following the loop, when the break function is called. It can be used in any loop statement, ... Read More

branching statement in Java

Kumar Varma
Updated on 30-Jul-2019 22:30:22

721 Views

Java programming language provides following types of decision making or branching statements.Java programming language provides following types of decision making statements.Sr.No.Statement & Description1if statementAn if statement consists of a boolean expression followed by one or more statements.2if...else statementAn if statement can be followed by an optional else statement, which executes when the boolean expression is false.3nested if statementYou can use one if or else if statement inside another if or else if statement(s).4switch statementA switch statement allows a variable to be tested for equality against a list of values.

branching statement in Java

Kumar Varma
Updated on 30-Jul-2019 22:30:22

721 Views

Java programming language provides following types of decision making or branching statements.Java programming language provides following types of decision making statements.Sr.No.Statement & Description1if statementAn if statement consists of a boolean expression followed by one or more statements.2if...else statementAn if statement can be followed by an optional else statement, which executes when the boolean expression is false.3nested if statementYou can use one if or else if statement inside another if or else if statement(s).4switch statementA switch statement allows a variable to be tested for equality against a list of values.

Incremental Java infinite loop

Abhinanda Shri
Updated on 12-Mar-2020 12:18:35

212 Views

ExampleFollowing is the required program −Live Demopublic class Tester {    public static void main(String args[]) {       int i = 0;       do {          i++;          System.out.println(i);       }while (true);    } }The output will keep printing numbers in sequential order.

Incremental Java infinite loop

Abhinanda Shri
Updated on 12-Mar-2020 12:18:35

212 Views

ExampleFollowing is the required program −Live Demopublic class Tester {    public static void main(String args[]) {       int i = 0;       do {          i++;          System.out.println(i);       }while (true);    } }The output will keep printing numbers in sequential order.

Infinite while loop in Java

Syed Javed
Updated on 27-Feb-2020 05:25:01

572 Views

Yes. Following while loop is a valid statement and causes an infinite loop.while(true);

Infinite while loop in Java

Syed Javed
Updated on 27-Feb-2020 05:25:01

572 Views

Yes. Following while loop is a valid statement and causes an infinite loop.while(true);

Advertisements