🔒 Closed Java "pyramid"..grabe ang hirap

Status
Not open for further replies.

Bayagkugan

Honorary Poster
Grabe sakit ng ulo ko dito haha..Any idea po clue or ano man??
Paki check na lang po yung nagawa ko at yung ouput dapat netong activity ko..
Sana may tumulong haha





Output.png Pyramid.png
 
May condition ka dapat sa loob ng loop. If 1st row, 1 circle lang ipiprint. If 7th row (index 6) naman dapat puro circle na ipiprint.

Yung 2nd to 6th row, dapat yung first at last lang ang may circle.

Ikaw na bahala hahaha goodluck.
 
if hindi 0 ang dapat i.display palitan mo lang ng space ganito ata " "


edit:
ok pala yung program mo. mag condition ka nlng if hindi dapat 0 ang display else " "
 
másáráp gawin ang mga ganito.
ako rin kulelat sa mga ganito.
here's how I see it pero di ko sure kung kaya ko i-code;
 

Attachments

  • fundtodo.jpg
    fundtodo.jpg
    39.6 KB · Views: 1
upload_2018-9-27_11-9-2.png

Code:
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("");
    }

lagay mo lng sa main, baka exam yan haha,
 
OK, 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
    }
   
}
 

Attachments

OK, 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
    }
  
}
Tanks po sir..Asahan ko po kayo sa mga susunod kong tanong ah..Laking tulong ng phc sa programming subject ko..Thanks PHC haha
 
OK, 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 explanation :)
 
Status
Not open for further replies.

Similar threads

About this Thread

  • 16
    Replies
  • 1K
    Views
  • 9
    Participants
Last reply from:
mnbvcxz14

Online now

Members online
735
Guests online
654
Total visitors
1,389

Forum statistics

Threads
2,275,125
Posts
28,960,808
Members
1,232,631
Latest member
marlaa1991
Back
Top