Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Could you explain to me what is happening in each line of code for the 2 codes pasted below. For example, this line of code

Could you explain to me what is happening in each line of code for the 2 codes pasted below.
For example, "this line of code is telling to print "prime numbers are.."
Prime Numbers:

class PrimeNumbers

{

public static void main (String[] args)

{

int i =0;

int num =0;

String primeNumbers = "";

for (i = 1; i

{

int counter=0;

for(num =i; num>=1; num--)

{

if(i%num==0)

{

counter = counter + 1;

}

}

if (counter ==2)

{

primeNumbers = primeNumbers + i + " ";

}

}

System.out.println("Prime numbers from 1 to 100 are:");

System.out.println(primeNumbers);

}

}

Fibonacchi Series:

public class FibonacciSeries

{

static void printFibonacciNumbers(int n)

{

int f1 = 0, f2 = 1, i;

if (n

return;

for (i = 1; i

{

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

int next = f1 + f2;

f1 = f2;

f2 = next;

}

}

public static void main(String[] args)

{

printFibonacciNumbers(8);

}

}

image text in transcribed
image text in transcribed
class Prime Numbers public static void main (String[] args) int i =0; int num =0; String prime Numbers = ""; for (i = 1; i =1; num--) if(i%num==0) counter = counter + 1; if (counter ==2) primeNumbers = primeNumbers + i +"| System.out.println("Prime numbers from 1 to 100 are:"); System.out.println(primeNumbers); Fibonacchi Series: public class Fibonacci Series static void printFibonacciNumbers(int n), int f1 = 0, f2 = 1, i; if (n

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Joe Celkos Data And Databases Concepts In Practice

Authors: Joe Celko

1st Edition

1558604324, 978-1558604322

More Books

Students also viewed these Databases questions