Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Need Help with passing arrays

Posted on 2000-05-16
2
Medium Priority
?
173 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 60 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

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…
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 …
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This video teaches viewers about errors in exception handling.
Suggested Courses

722 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