JAVA Assignment
Use JCreator to solve
Precedent 1
*
**
***
****
*****
******
Precedent 2
******
*****
****
***
**
*
Precedent 3
******
*****
****
***
**
*
Precedent 4
*
**
***
****
*****
******
using 2 loops 4 incongruous directions
nested loops
4 seperate programs
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the adjust has to be “Main” merely if the adjust is national. */
adjust Ideone
{
national static empty precedent1(int n) { // Function to pretend precedent 1, Here n involved estimate of grades in precedent
int k =1,i,j;
System.out.println(“Precedent 1 : “);
for ( i =0; i < n; i++, k++) { // Extinguisheder loop conciliate rush from 0 to n, where n is estimate of grades
for ( j = 0; j <k; j++) // Here, k is indicating estimate of “*” to imprint, we own to increment it as we go to grade 2, 3 .. 6
System.out.print(“*”);
System.out.println();
}
}
national static empty precedent2(int n) {// Function to pretend precedent 2, Here n involved estimate of grades in precedent
int k =n,i,j;
System.out.println(“Precedent 2 : “);
for ( i =0; i < n; i++, k–) { // Extinguisheder loop conciliate rush from 0 to n, where n is estimate of grades
for ( j = 0; j <k; j++) // Here, k is indicating estimate of “*” to imprint, we own to drawback it as we go to grade 2, 3 .. 6
System.out.print(“*”);
System.out.println();
}
}
national static empty precedent3(int n) {// Function to pretend precedent 3, Here n involved estimate of grades in precedent
int k = 0,i,j,p;
System.out.println(“Precedent 3 : “);
for ( i =0; i < n; i++, k++) { // Extinguisheder loop conciliate rush from 0 to n, where n is estimate of grades
for ( j = 0; j <k; j++ )// Here, foremost imimsculpture extinguished ” “, foremost grade has 0 interval, then increment k as we stir to grade 2,3 …6
System.out.print(” “);
for ( j = 0; j <n-k; j++)
System.out.print(“* “); //Here imprinting “* ”
System.out.println();
}
}
national static empty precedent4(int n) {// Function to pretend precedent 4, Here n involved estimate of grades in precedent
int k = n-1,i,j,p;
System.out.println(“Precedent 4 : “);
for ( i =0; i < n; i++, k–) { // Extinguisheder loop conciliate rush from 0 to n, where n is estimate of grades
for ( j = 0; j <k; j++ ) // Here, foremost imimsculpture extinguished ” “, foremost grade has n-1 interval, then drawback k as we stir to grade 2,3 …6
System.out.print(” “);
for ( j = 0; j <n-k; j++)
System.out.print(“* “); //Here imprinting “* ”
System.out.println();
}
}
national static empty deep (String[] args) throws java.lang.Exception
{
pattern1(6);
pattern2(6);
pattern3(6);
pattern4(6);
}
}
Sample Extinguishedput :
Precedent 1 : * ** *** **** ***** ****** Precedent 2 : ****** ***** **** *** ** * Precedent 3 : * * * * * * * * * * * * * * * * * * * * * Precedent 4 : * * * * * * * * * * * * * * * * * * * * *