May ganto din kayong exercise?..Or tinatry lang?Nag tatry din ako ang hirap hahahaha.
Tinatry lang. Yung right side nalang kulang e.May ganto din kayong exercise?..Or tinatry lang?
Pano yung code mo po?..Sakin di ko alam tanggalin yung O sa row 3-6 eh ahhaaTinatry lang. Yung right side nalang kulang e.
Pano yung code mo po?..Sakin di ko alam tanggalin yung O sa row 3-6 eh ahhaa

for(int x = 1; x <= 7; x++){
for(int y = 1; y <= 7-x; y++){
System.out.print(" ");
}
for(int z = 1; z<= x; z++){
if(x >= 3 && x < 7){
if(z >1 && z<x){
System.out.print(" ");
}else{
System.out.print("0 ");
}
}else{
System.out.print("0 ");
}
}
for(int z = 1; z <= 7-x; z++){
System.out.print(" ");
}
System.out.println("");
}
public class MainApp {
//Ito lang ang papalitan. Kumbaga Switch ng ilaw.
static int pyramidHeight = 8; //PILIIN kung ano ang height ng pyramid na gusto
static int first = 1; //PILIIN lang kung saan gusto magsimula ang FOR-LOOP (0 or 1)
//Ito naman optional pampaganda
static String image = " O "; //Kung anong gustong image
static String blank = " "; //Para sa blank spaces
static String divider = " | "; //Divider lang
static int pyramidColumns = (pyramidHeight * 2)-first; //AUTOMATIC ITO
//************************start ng program************************//
public static void main(String[] args) {
for(int row=first; row<=pyramidHeight; row++) {
printColDivider();
for(int col=first; col<=pyramidColumns; col++) {
printFirst(row,col);
printInBetweens(row,col);
printLast(row,col);
printColDivider();
}
goToNextRow();
}
}
//************************end ng program************************//
//Mga METHODS
//CONDITION 2: Top of pyramid or row 1
static void printFirst(int rowAddress, int colAddress) {
if(rowAddress==first && colAddress==pyramidHeight) {
printImage();
}
if(rowAddress==first && colAddress!=pyramidHeight) {
printBlank();
}
}
//CONDITION 1: Body of pyramid
static void printInBetweens(int rowAddress, int colAddress) {
if(rowAddress>first && rowAddress<pyramidHeight) {
if(colAddress==pyramidHeight-(rowAddress-first)) {
printImage();
}
else if(colAddress==pyramidHeight+(rowAddress-first)) {
printImage();
} else {
printBlank();
}
}
}
//CONDITION 3: Base of pyramid or last row
static void printLast(int rowAddress, int colAddress) {
if(rowAddress==pyramidHeight) {
printImage();
}
}
//MGA HELPER METHODS LANG ITO - pampaganda
static void printImage() {
System.out.print(image); //prints the X or whatever character u want
}
static void printBlank() {
System.out.print(blank); //prints blank cell
}
static void printColDivider() { //prints the divider line between cells
System.out.print(divider);
}
static void goToNextRow() {
System.out.println("\n\n"); //prints next row
}
}
Tanks po sir..Asahan ko po kayo sa mga susunod kong tanong ah..Laking tulong ng phc sa programming subject ko..Thanks PHC hahaOK, dahil kulelat ako sa mga ganito.
I took time to analyze it.
Heto ang aking findings. Kung meron kayong ibang ideas, I am interested to know also.
Ginawa ko siyang FLEXIBLE para kahit gaano kataas ang height ng pyramid na gusto ay puwede.
Download PDF and also here's the Java code.
Code:public class MainApp { //Ito lang ang papalitan. Kumbaga Switch ng ilaw. static int pyramidHeight = 8; //PILIIN kung ano ang height ng pyramid na gusto static int first = 1; //PILIIN lang kung saan gusto magsimula ang FOR-LOOP (0 or 1) //Ito naman optional pampaganda static String image = " O "; //Kung anong gustong image static String blank = " "; //Para sa blank spaces static String divider = " | "; //Divider lang static int pyramidColumns = (pyramidHeight * 2)-first; //AUTOMATIC ITO //************************start ng program************************// public static void main(String[] args) { for(int row=first; row<=pyramidHeight; row++) { printColDivider(); for(int col=first; col<=pyramidColumns; col++) { printFirst(row,col); printInBetweens(row,col); printLast(row,col); printColDivider(); } goToNextRow(); } } //************************end ng program************************// //Mga METHODS //CONDITION 2: Top of pyramid or row 1 static void printFirst(int rowAddress, int colAddress) { if(rowAddress==first && colAddress==pyramidHeight) { printImage(); } if(rowAddress==first && colAddress!=pyramidHeight) { printBlank(); } } //CONDITION 1: Body of pyramid static void printInBetweens(int rowAddress, int colAddress) { if(rowAddress>first && rowAddress<pyramidHeight) { if(colAddress==pyramidHeight-(rowAddress-first)) { printImage(); } else if(colAddress==pyramidHeight+(rowAddress-first)) { printImage(); } else { printBlank(); } } } //CONDITION 3: Base of pyramid or last row static void printLast(int rowAddress, int colAddress) { if(rowAddress==pyramidHeight) { printImage(); } } //MGA HELPER METHODS LANG ITO - pampaganda static void printImage() { System.out.print(image); //prints the X or whatever character u want } static void printBlank() { System.out.print(blank); //prints blank cell } static void printColDivider() { //prints the divider line between cells System.out.print(divider); } static void goToNextRow() { System.out.println("\n\n"); //prints next row } }
Salamat po sa magandang explanationOK, dahil kulelat ako sa mga ganito.
I took time to analyze it.
Heto ang aking findings. Kung meron kayong ibang ideas, I am interested to know also.
Ginawa ko siyang FLEXIBLE para kahit gaano kataas ang height ng pyramid na gusto ay puwede.
Download PDF and also here's the Java code.
Code:public class MainApp { //Ito lang ang papalitan. Kumbaga Switch ng ilaw. static int pyramidHeight = 8; //PILIIN kung ano ang height ng pyramid na gusto static int first = 1; //PILIIN lang kung saan gusto magsimula ang FOR-LOOP (0 or 1) //Ito naman optional pampaganda static String image = " O "; //Kung anong gustong image static String blank = " "; //Para sa blank spaces static String divider = " | "; //Divider lang static int pyramidColumns = (pyramidHeight * 2)-first; //AUTOMATIC ITO //************************start ng program************************// public static void main(String[] args) { for(int row=first; row<=pyramidHeight; row++) { printColDivider(); for(int col=first; col<=pyramidColumns; col++) { printFirst(row,col); printInBetweens(row,col); printLast(row,col); printColDivider(); } goToNextRow(); } } //************************end ng program************************// //Mga METHODS //CONDITION 2: Top of pyramid or row 1 static void printFirst(int rowAddress, int colAddress) { if(rowAddress==first && colAddress==pyramidHeight) { printImage(); } if(rowAddress==first && colAddress!=pyramidHeight) { printBlank(); } } //CONDITION 1: Body of pyramid static void printInBetweens(int rowAddress, int colAddress) { if(rowAddress>first && rowAddress<pyramidHeight) { if(colAddress==pyramidHeight-(rowAddress-first)) { printImage(); } else if(colAddress==pyramidHeight+(rowAddress-first)) { printImage(); } else { printBlank(); } } } //CONDITION 3: Base of pyramid or last row static void printLast(int rowAddress, int colAddress) { if(rowAddress==pyramidHeight) { printImage(); } } //MGA HELPER METHODS LANG ITO - pampaganda static void printImage() { System.out.print(image); //prints the X or whatever character u want } static void printBlank() { System.out.print(blank); //prints blank cell } static void printColDivider() { //prints the divider line between cells System.out.print(divider); } static void goToNextRow() { System.out.println("\n\n"); //prints next row } }
