OK here is my code to print all prime numbers less than 100 and also print the first 36 numbers in the fibonacci series. I want to change it so that the fibonacci prints 9 numbers per line and the prime numbers print in 5 per line. Im new to learning loops and nested loops and cant seem to figure this out. thanks, lee
//course: CSC 190;
//project:lab9;
//date:3/25/201;
//purpose:Print all prime numbers less than 100 and print first 36 fibonacci numbers
//author:
class main
{
void fib()
{
int n0 = 1, n1 = 1, n2; // Initialize variables
System.out.print(n0 + " " + n1 + " "); //Print first and second terms of the series
for (int y = 0; y < 34; y++)
{ // Loop for the next 34 terms
n2 = n1 + n0; // Next term is sum of previous two
System.out.print(n2 + " "); // Print it out
n0 = n1; // First previous becomes 2nd previous
n1 = n2; // And current number becomes previous
}
System.out.println(); // Terminate the line
}
void prime()
{
int p;
for(int i=2;i<100;i++)
{
p=0;
for(int j=2;j<i;j++)
{
if(i%j==0)
p=1;
}
if(p==0)
System.out.print(i+" ");
}
}
}
class hw4
{
public static void main(String [] args)
{
main M = new main();
M.fib();
System.out.println();
M.prime();
}
}