Results 1 to 6 of 6
  1. #1
    Shyam Singh is offline Member
    Join Date
    Jun 2008
    Posts
    48
    Rep Power
    0

    Question wat is the problem in the code ?

    class infoarr {

    public char[]infoarr cunvert() {

    char []c=new char[26];

    for(int i=0;i<26;i++) {

    c[i]=(char)('A'+i);
    }
    return c;
    }

    public static void main(String []a) {

    infoarr in=new infoarr();
    char[]s=in.cunvert();

    for(char var:s) {
    System.out.println(ar);
    }

    }
    }

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,412
    Rep Power
    25

    Default

    If you get errors, please copy and paste them here.
    Don't expect anyone to do your work of compiling a pgm to see the errror messages.

  3. #3
    Shyam Singh is offline Member
    Join Date
    Jun 2008
    Posts
    48
    Rep Power
    0

    Default Code & error i faced --

    class infoarr {

    public char[]infoarr cunvert() {

    char []c=new char[26];

    for(int i=0;i<26;i++) {

    c[i]=(char)('A'+i);
    }
    return c;
    }

    public static void main(String []a) {

    infoarr in=new infoarr();
    char[]s=in.cunvert();

    for(char var:s) {
    System.out.println(var);
    }

    }

    error -->

    jdk1.5.0_06/bin/infoarr.java [3:1] ';' expected
    public char[]infoarr cunvert() {
    ^
    1 error
    Errors compiling infoarr.

    Sorry Norm .. & thanks

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,412
    Rep Power
    25

    Default

    public char[]infoarr cunvert() {
    is there a black after the ]

  5. #5
    Shyam Singh is offline Member
    Join Date
    Jun 2008
    Posts
    48
    Rep Power
    0

    Default No blank space after ],it is like char[]infoarr

    Quote Originally Posted by Norm View Post
    is there a black after the ]
    it is like char[]infoarr

  6. #6
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    The type declaration is a type, eg, a char array such as char[].
    Don't put the variable name in it.
    Java Code:
    class infoarr { 
    
        public char[] cunvert() {
            char []c=new char[26];
    
            for(int i=0;i<26;i++) {
                c[i]=(char)('A'+i);
            }
            return c; 
        }
    
        public static void main(String[] args) {
            infoarr in = new infoarr();
            char[] s = in.cunvert();
    
            for(char var : s) {
                System.out.println(var); 
            }
        }
    }

Similar Threads

  1. What is the answer yo my problem with this code
    By masaka in forum New To Java
    Replies: 4
    Last Post: 03-26-2008, 06:33 AM
  2. Problem with code
    By jvasilj1 in forum New To Java
    Replies: 5
    Last Post: 02-02-2008, 08:34 AM
  3. Problem with code
    By oregon in forum New To Java
    Replies: 3
    Last Post: 08-05-2007, 05:57 PM
  4. Problem with zero in my code
    By fernando in forum New To Java
    Replies: 1
    Last Post: 08-05-2007, 06:39 AM
  5. Problem with my first code
    By paul in forum New To Java
    Replies: 2
    Last Post: 07-26-2007, 04:09 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •