help me plz ... stilll a beginner

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pralu
    New Member
    • Mar 2008
    • 34

    help me plz ... stilll a beginner

    public class StringExp
    {
    public static void main(String[] args)
    {
    String[] a = {1,2,3,3};
    String[] b;
    System.out.prin tln(a);
    }
    }

    it gives the error while compiling :
    the errors is of incompatible types, can any one tell me whether we can have the string as an array if yes then how to initialize it...
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by pralu
    public class StringExp
    {
    public static void main(String[] args)
    {
    String[] a = {1,2,3,3};
    String[] b;
    System.out.prin tln(a);
    }
    }

    it gives the error while compiling :
    the errors is of incompatible types, can any one tell me whether we can have the string as an array if yes then how to initialize it...
    You're not using String[] b and you should either do this: int[] a = { 1 2, 3, 3 }
    or String[] a = { "1", "2", "3", "3" }; ints aren't Strings nor vice versa.

    kind regards,

    Jos

    Comment

    • pralu
      New Member
      • Mar 2008
      • 34

      #3
      Originally posted by JosAH
      You're not using String[] b and you should either do this: int[] a = { 1 2, 3, 3 }
      or String[] a = { "1", "2", "3", "3" ,"4","5");in ts aren't Strings nor vice versa.

      kind regards,

      Jos

      thanks i got it ... now if i want to caompare the two strings and do't want any no.s do be reapeted in second string ....

      like in 1st string we have elements as 1,2,3,3,4,5.now we have to copy this to second string having output as 1,2,3,4,5

      Comment

      • mia023
        New Member
        • May 2007
        • 89

        #4
        Originally posted by pralu
        thanks i got it ... now if i want to caompare the two strings and do't want any no.s do be reapeted in second string ....

        like in 1st string we have elements as 1,2,3,3,4,5.now we have to copy this to second string having output as 1,2,3,4,5
        you should loop through every element in the array and print its index.

        Comment

        • JosAH
          Recognized Expert MVP
          • Mar 2007
          • 11453

          #5
          Originally posted by pralu
          thanks i got it ... now if i want to caompare the two strings and do't want any no.s do be reapeted in second string ....

          like in 1st string we have elements as 1,2,3,3,4,5.now we have to copy this to second string having output as 1,2,3,4,5
          Where did those "4" and "5" come from in your quotation of my reply?

          btw, read the API documentation of the Arrays class and the Map
          interfase and its implementing classes; that'll do.

          kind regards,

          Jos

          Comment

          Working...