Home Robotics C++ Physics II AP Physics B Electronics AP Java Astronomy Independent Study Summer Session Contests  About
                                                       

What does this code do?                       Answer

 

import gpdraw.*;

import java.util.Random;

import java.awt.Color;

 

public class Pictures

{

   public static void printTable (int rownum, int colnum)

   {

      int  row, col;

 

      System.out.println();

      System.out.print("      ");

      for (col = 1; col <= colnum; col++)

      System.out.printf("%4d", col);

      System.out.println();

      System.out.println();

 

      for (row = 1; row <= rownum; row++)

      {

         System.out.printf("%4d" + "  ", row);

 

         for (col = 1; col <= colnum; col++)

         {

            System.out.printf("%4d", row * col);

         }

 

         System.out.println();

      }

   }

 

   public static void pyramid (int n)

   {

      int line, blanks, stars, temp;

 

      System.out.println();

      for (line=1; line<=n; line++)

      {

         blanks = n-line;

         stars = line*2-1;

         for (temp=1; temp<=blanks; temp++)

         {

            System.out.print(" ");

         }

 

         for (temp=1; temp<=stars; temp++)

         {

            System.out.print("*");

         }

 

         System.out.println();

      }

   }

 

  public static void drawSunburst()

  {

    int max = 500;

    DrawingTool pen = new DrawingTool(new SketchPad(500, 500));

      Random die = new Random();

 

    pen.down();

   

    for (int line = 0; line < 360; line++)

    {

      pen.setColor(new Color(die.nextInt(256), die.nextInt(256), die.nextInt(256)));

 

      pen.forward(max/2 - 30);

      pen.backward(max/2 - 30);

      pen.turnRight(1);

    }

  }

 

}

 

public class picturesDriver

{

      public static void main(String[] args)

      {

            Pictures mystery = new Pictures();

            mystery.pyramid(6);

            mystery.drawSunburst();

            mystery.printTable(6,6);

      }

}