Solved

Need Help with passing arrays

Posted on 2000-05-16
2
166 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will learn how to implement Singleton Design Pattern in Java.

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now