What's new

Java Patulong po di pa kasi naturo

Activity 2 - You do not have permission to view the full content of this post. Log in or register now.
[CODE lang="java" title="Act2"] public static void printStars(int n)
{
int i, j;

// outer loop to handle number of rows
// n in this case
for(i=0; i<n; i++)
{

// inner loop to handle number of columns
// values changing acc. to outer loop
for(j=0; j<=i; j++)
{
// printing stars
System.out.print("* ");
}

// ending line after each row
System.out.println();
}
}[/CODE]

Acitvity 3 - You do not have permission to view the full content of this post. Log in or register now.
[CODE lang="java" title="Act3"] static void solidSquare(int rows)
{
int i, j;
for (i = 1; i <= rows; i++)
{
// Print stars after spaces
for (j = 1; j <= rows; j++)
System.out.print("*");

// Move to the next line/row
System.out.print("\n");
}

} [/CODE]

Activity 4 -
[CODE lang="java" title="Act5"]static void act5(int[] arr, int multi){
for(int i = 0; i < arr.length(); i++)
System.out.print(arr * multi + " ");
}[/CODE]
Activity 5 - You do not have permission to view the full content of this post. Log in or register now.
[CODE lang="java" title="Act4"]import java.io.*;

class GFG {
public int factorial(int i)
{
if (i == 0)
return 1;
return i * factorial(i - 1);
}
public static void main(String[] args)
{
int n = 4, i, j;
GFG g = new GFG();
for (i = 0; i <= n; i++) {
for (j = 0; j <= n - i; j++) {
System.out.print(" "); // for left spacing
}
for (j = 0; j <= i; j++) {
// nCr formula
System.out.print(
" "
+ g.factorial(i)
/ (g.factorial(i - j)
* g.factorial(j)));
}
System.out.println(); // for newline
}
}
}[/CODE]

Activity 1 - You do not have permission to view the full content of this post. Log in or register now.
[CODE lang="java" title="Act1"]public static void printNums(int n)
{
int i, j,num;

// outer loop to handle number of rows
// n in this case
for(i=0; i<n; i++)
{
// initialising starting number
num=1;

// inner loop to handle number of columns
// values changing acc. to outer loop
for(j=0; j<=i; j++)
{
// printing num with a space
System.out.print(num+ " ");

//incrementing value of num
num++;
}

// ending line after each row
System.out.println();
}
}[/CODE]
Activity 6
[CODE lang="java" title="Act6"]static void sumArray(int[] arr){
int sum = 0;
for(int i = 0; i < arr.length(); i++)
sum += arr;
System.out.println("Sum: " + sum);
}[/CODE]
 
[XX='Anthony_111, c: 741996, m: 841133'][/XX] naka method type po yan ts, ikaw ang bahala kung gusto mo ganyan na o baguhin mo pa.
 

Similar threads

Back
Top