Computer Science, asked by CHEMISTRYking, 1 year ago

write a Java program to print the pattern using for loop

*****
****
***
**
*​

Answers

Answered by nathandrake51
0

public class JavaExample {

public static void main(String[] args) {

int count = 7, num1 = 0, num2 = 1;

System.out.print("Fibonacci Series of "+count+" numbers:");

for (int i = 1; i <= count; ++i)

{

System.out.print(num1+" ");

/* On each iteration, we are assigning second number

* to the first number and assigning the sum of last two

* numbers to the second number

*/

int sumOfPrevTwo = num1 + num2;

num1 = num2;

num2 = sumOfPrevTwo;

}

}

}

Output:

Fibonacci Series of 7 numbers:0 1 1 2 3 5 8

Example 2: Displaying Fibonacci Sequence using while loop

public class JavaExample {

public static void main(String[] args) {

int count = 7, num1 = 0, num2 = 1;

System.out.print("Fibonacci Series of "+count+" numbers:");

int i=1;

while(i<=count)

{

System.out.print(num1+" ");

int sumOfPrevTwo = num1 + num2;

num1 = num2;

num2 = sumOfPrevTwo;

i++;

}

}

}


CHEMISTRYking: wrong
nathandrake51: plz mark me as brainliest
CHEMISTRYking: how to mark
Answered by Anonymous
3

&lt;a href="https://brainly.in/question/6759103?utm_source=android&amp;utm_medium=share&amp;utm_campaign=question"&gt;CLICK HERE&lt;/a&gt;

Similar questions