Question
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
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);
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started