Solved

Need Help with passing arrays

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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

628 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