0

How is it to pass int [] rank to main method?

public class Card
{
    private int [] rank= new int [13];
    private String [] suit={"Spades","Hearts","Diamonds","Clubs"};
    private static void rankMaker (int []rank)
    {
        for (int i=1;i<=13;i++)
        rank[i]=i;
    }
    public static void main (String []args)
    {
        System.out.println("Jack ="+rank[11]);
    }
}

Ignoring the way I am making this deck, what I want to know is how generally can I use "int [] rank" (or any other variable declared outside the main) in other methods?

Edited by pyTony: fixed formating

3
Contributors
2
Replies
3
Views
12 Years
Discussion Span
Last Post by server_crash
0

You can't, period.

The normal way is to have the main method do nothing except handle commandline arguments, create a single instance of the application (usually its own class), and start that instance.

0

Just in case, here's kindof what he's talking about:

public class Card
{
	private int [] rank= new int [13];
	private String [] suit={"Spades","Hearts","Diamonds","Clubs"}; //Not used?


	public Card()
	{
		super();
	}
	


	public void setRanks(int []rank)
	{
		for (int i=1;i<=13;i++)
		{
			rank[i]=i;
		}
	}


	public int getRankAt(int index)
	{
		return this.rank[index];
	}
}


class TestCard
{
	public static void main(String[] args)
	{
		[B]Card c = new Card();
		System.out.println(c.getRankAt(11) + "");[/B]
	}
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.