Ask Question

Name:
Title:
Your Question:

Answer Question

Name:
Your Answer:
User Submitted Source Code!


Description:
  DataTable
Language: JAVA
Code:
import java.util.Scanner;

public class DataTable
{
   private int num;
   
   public DataTable( int theNum)
   {
      num = theNum;
   }
   
   public void setNum(int theNum)
   {
      num = theNum;
   }
   
   public int getNum()
   {
      return num;
   }
   
   public void report()
   {
      int counter = 1;
      double square;
      double root;
      
      while(counter <= num)
      {
         square = num * num;
         
         root = Math.sqrt(num);
         
         System.out.println("Number   Squared   Square Root");
         System.out.printf("%d\n        %d\n      %d\n", num, square, root);
         
         counter++;
      }
   }
   
   public static void main(String[] args)
   {
      Scanner input = new Scanner(System.in);
      
      System.out.print("Length (as integer) of data table? ");
      int num = input.nextInt();
      
      DataTable myDataTable = new DataTable(num);
      myDataTable.report();
   }
}
Comments: