Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Help using arrays in java

807599Nov 26 2006 — edited Nov 26 2006
HI all,
I am working on a program that will print out my initials 'A' and 'T' using arrays. I am asked to initialize the first intial to '*' and the second intial to '@'. I wrote the code but the output is wrong. Can someone help me by letting me know what I am doing wrong in my arrray?I just get back my array of 30X30. I also wrote a driver but when I run the program, I really appreciate it so much.
public class Initial
{
	private char whichinitial ;
	private int MAX =30;//Maximum amount for 2-d Matrix
	char[][] letterMatrix = new char[MAX][MAX];//2-d Array 30 x30
	private boolean first = true;
	
	public Initial()
	{ //FIlls Array full of '*'s
		whichinitial = '*';
		for(int i=0;i< MAX;i++)
			for(int j=0;i< MAX;i++)
				letterMatrix[i][j] = whichinitial;
	}
	
	public void setLetter(char letter)
	{//Setter for Letter
		 whichinitial = letter;
	}
	
	public char getLetter()
	{//Getter for Letter
		return whichinitial;
	}
	
	public void firstLetter()
	{ //Creates an A shape
		for(int i=0;i< MAX;i++)
		{
		  for(int j=0;j< MAX;j++)
		  {
		  	 if((i>0)|| ((i<6) || ((j>0) && (j<29))))
			 {
			 	letterMatrix[j] =whichinitial;
}
}
}
}

public void secondLetter()
{//Creates an T shape
first = false;

for(int i=0;i <MAX;i++)
{
for(int j=0;j <MAX;j++)
{
if((i>1) ||(j < 29)||(j>5)||(i>10))
{
letterMatrix[i][j] = whichinitial;
}
}
}
}

public void display()
{//Displays the Initials
if(first)
{
System.out.println("\n \n \n My First Initial," + whichinitial + ", follows:");
}
else
{
System.out.println("\n \n \n My Last Initial," + whichinitial + ", follows:");
}
for(int i=0;i <MAX;i++)
{
System.out.println();

for(int j=0;j <MAX;j++)
{
if(letterMatrix[i][j] == '*')
{
System.out.print(" ");
}
else
{
System.out.print(letterMatrix[i][j]);
}
}
}
}
}

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 24 2006
Added on Nov 26 2006
10 comments
140 views