Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Method Help
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
samanthaxc




PostPosted: 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;
}
}



Unit1Act7aVer4.java
 Description:

Download
 Filename:  Unit1Act7aVer4.java
 Filesize:  588 Bytes
 Downloaded:  151 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
ishidon




PostPosted: 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;
    }
   
}
samanthaxc




PostPosted: Thu Mar 07, 2013 9:20 pm   Post subject: Re: Method Help

Thank You!
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: