FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Java - char array





GavinJaynes
Hey guys is any one awesome at java I have an assignment on char arrays as not to use the String class. Any ideas or Tips.
jackill
Like:

Code:
public class MainClass {

  public static void main(String[] arg) {
    char[] ch = {'a','b','c','d'};
    System.out.println(String.valueOf(ch));   

  }
}


Code:
public class MainClass
{
   public static void main( String args[] )
   {
      String s1 = "hello there";
      char charArray[] = new char[ 5 ];

      System.out.printf( "s1: %s", s1 );

      for ( int count = s1.length() - 1; count >= 0; count-- )
         System.out.printf( "%s ", s1.charAt( count ) );

      // copy characters from string into charArray
      s1.getChars( 0, 5, charArray, 0 );
      System.out.print( "\nThe character array is: " );

      for ( char character : charArray )
         System.out.print( character );
   }
}


?
thetinyclam
What exactly are you asking for this assignment...? Lol, be a little more descriptive so we can help.
AftershockVibe
I'd be interested to know what the point of this is like thetinyclam. Hopefully it's about immutability etc rather than just "because I say so". Smile

jackill is right though... define an array of chars like you would define an array of anything else. Awesomeness definintely not required.
GavinJaynes
Hey guys thanks for all the responses - what the assignment asks is:

To write a class called MyString, the only data structure I can implement is an array of char characters. The class MyString has a single constructor that takes a char array as a parameter. The input char array is the string this object will represent. Hence, this input char array will be assigned to the char array field. Implement this constructor.

Then there are a bunch of methods to implement, but I'm not asking for someone to do my assignment, just help my understand what the hell all that means? And yes I'd also like to know what the point of this assignment is...

Any help much appreciated , and thanks again for help already - Jackill
ThePolemistis
GavinJaynes wrote:
Hey guys thanks for all the responses - what the assignment asks is:

To write a class called MyString, the only data structure I can implement is an array of char characters. The class MyString has a single constructor that takes a char array as a parameter. The input char array is the string this object will represent. Hence, this input char array will be assigned to the char array field. Implement this constructor.

Then there are a bunch of methods to implement, but I'm not asking for someone to do my assignment, just help my understand what the hell all that means? And yes I'd also like to know what the point of this assignment is...

Any help much appreciated , and thanks again for help already - Jackill


A String is essentially an array of characters. However, maybe you need declare char[] yourChar rather than String myString, albeit it is essentially the same.
Then you would need to implement a constructor - which essentially imeans you will be creating an instance of class. This should take char as an array as the parameter. Therefore you need a mthod for this, and you would call it from the main method.

Seems pretty trivial to me... the other methods probably define precisely what needs to be done.
Related topics
picture slide show (java)
Java Game
Java
Fortran Tutorials(77)
Java project coupling problems
C++ Assignment! its about string.h
C++ int to char and char to int
[C] Splitting names program
[C++] Double/Float to char []
java generics
JAVA - random name generator
Recursive functions in java
Generic arrays in Java
Temporary code for POJ 1077
Reply to topic    Frihost Forum Index -> Computers -> Computer Problems and Support

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.