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?

Recommended Answers

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.

Jump to Post

All 2 Replies

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.

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]
	}
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.