Solved

Need Help with passing arrays

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
micro services vs rest web services 16 103
HashTable highest marks enumeration alternative 9 37
runtime exception 2 27
Which non-HTML GUI front end to use with Java? 3 21
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
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.

776 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