Computer Science Canada

Method Help

Author:  samanthaxc [ Thu Mar 07, 2013 7:45 pm ]
Post subject:  Method Help

My program is supposed to calculate the squares of the numbers from 1 to twelve, then display them in a chart for showing the number and their square. I am supposed to use two methods but i'm having trouble how. Please help and tell me what is wrong



import java.io.*;

public class findingSquares
{
public static void main (String [] args) throws IOException
{

System.out.println("Number " + "Square");

findSquare root = new findSquare();

int numSquare = root.square();

int num = 0;

while (num >= 0 && num <= 11)
{
num++;
System.out.println(num + "\t" + numSquare);
}
}


public static int findSquare (String square)
{
int num = 1;
int numSquare = num * num;


return numSquare;
}
}

Author:  ishidon [ Thu Mar 07, 2013 8:23 pm ]
Post subject:  Re: Method Help

I believe what you want is.

code:

public class findingSquares {
    public static void main (String [] args){

        System.out.println("Number \tSquare");
       
        for (int num = 1; num <= 12; num ++) {
           
            System.out.println(Integer.toString(num) + "\t" + Integer.toString(findSquare(num)));
        }
    }
   
    public static int findSquare (int num) {
        int numSquare = num * num;
   
        return numSquare;
    }
   
}

Author:  samanthaxc [ Thu Mar 07, 2013 9:20 pm ]
Post subject:  Re: Method Help

Thank You!


: