Solved

Need Help with passing arrays

Posted on 2000-05-16
2
170 Views
Last Modified: 2010-05-18
I'm getting an error of "Incompatible type for=. Can't convert char[] to char."  I would like to pass a int value to getCard and return a char type.  Is this possible? And how do I do it?


import java.io.*;
 
public class Game {
   
public char getCard(int a[])
    {  
      char face [];               // declare reference to an array
      face= new char[52];   // dynamically allocate array    
     
      String[] name={"Ace of Diamonds"}  ;
      if (a[0]==1)
           {
         face[0]=name[0].toCharArray(); // Create the array from the string
         return face;
           }
           }
   public void init (
   
    )
    throws IOException
    {
     
     
       int card[];                // declare reference to an array
       card=  new int [1];   // dynamically allocate array
     
       int name[];                // declare reference to an array
       name=  new int [52];  // dynamically allocate array            
       int i =0;            
   
  InputStreamReader isr= new InputStreamReader(System.in);
     System.out.print("Would you like to play a Game? (Y or N)");
     BufferedReader in= new BufferedReader(isr);
     while(true) {
     String input= in.readLine();      // System.out.println("Echo:" + input);
      if (input.equals("Y"))
         do {
                 if (i==0) {
                     card[0]=1;    
                     getCard(card);
                           }
                           } while  ( i < card.length);
      if (input.equals("x"))
           break;
                  }   //while ending
               } // main ending
            }  // class ending
0
Comment
Question by:Lisag
  • 2
2 Comments
 
LVL 1

Expert Comment

by:karthicraja
ID: 2814940
The program is not clear, your comments and the code differs a lot, give more information
0
 
LVL 1

Accepted Solution

by:
karthicraja earned 20 total points
ID: 2814946
Is this what do you want ??.

public static char[] getCard(int a[])
{    
char face [];// declare reference to an array
face= new char[52];// dynamically allocate array    
String name="Ace of Diamonds";
if (a[0]==1)
{
face=name.toCharArray(); // Create the array from the string
}
return face;
}

init()
{
int a[] = new int[4];
a[0] = 1;
char []b = getCard(a);
}
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question