Results 1 to 13 of 13

Thread: Add char

  1. #1
    analins's Avatar
    analins is offline Member
    Join Date
    Sep 2011
    Posts
    6
    Rep Power
    0

    Default Add char

    Dear,

    How do I add the characters d1, d2 and d3?

    Thanks.


    Java Code:
    public class ClassC {  
      
        public ClassC() {  
      
            
      
            ClasseA a = new ClasseA();  
            char[] d1=a.getPass1().getPassword();  
      
            
      
            ClasseB b = new ClasseB();  
            char[] d2=a.getPass2().getPassword();  
      
            
      
            ClasseC c = new ClasseC();  
            char[] d3=a.getPass3().getPassword();  
      
            
      
            // Add d1+d2+d3  
              
      
            
      
        }  
      
        public static void main(String args[] ) {  
      
            ClassC classC = new ClassC();  
      
        }  
      
    }

  2. #2
    Addez is offline Senior Member
    Join Date
    Aug 2009
    Posts
    294
    Rep Power
    0

    Default Re: Add char

    char[] add = new char[d1.length+d2.length+d3.length];
    int i = 0;

    for(char c : d1){
    add[i] = c;
    i++;
    }
    for(char c : d2){
    add[i] = c;
    i++;
    }
    for(char c : d3){
    add[i] = c;
    i++;
    }

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

    Default Re: Add char

    How do I add the characters d1, d2 and d3?
    char are a type of integer. They can be added directly
    How have you tried to add them?
    What result do you expect?
    Here is a statement that adds two characters:

    System.out.println((int)'2' + " " + ('2' + '2')); // 50 100

  4. #4
    analins's Avatar
    analins is offline Member
    Join Date
    Sep 2011
    Posts
    6
    Rep Power
    0

    Default Re: Add char

    I want to add and then compare with equals. How do I?
    I want a variable aux = d1 + d2 + d3 Sepo compare the sen = "abc". A comparison of password.

    thanks.

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

    Default Re: Add char

    Java Code:
    aux = d1 + d2 + d3
    What data type is aux?
    Java Code:
    sen = "abc"
    The variable: sen looks like a String with 3 characters. Do you want to build a String from the three characters: d1, d2 and d3 and compare that String with the String: sen?

    Can you explain what you are trying to do?

  6. #6
    analins's Avatar
    analins is offline Member
    Join Date
    Sep 2011
    Posts
    6
    Rep Power
    0

    Default Re: Add char

    That's right. The values ​​d1, d2 and d3 each one belongs to a class, I want to add these values ​​and compare with "abc", String actual = "abc".


    (this password problem and banks - ATM in each screen (frame) the User prescionar a button under your password with letters of the alphabet)

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

    Default Re: Add char

    You can create a String with characters by putting the characters in an array and using the String class's constructor to build the String. See the API doc for the String class for an example.
    Java Platform SE 6

  8. #8
    analins's Avatar
    analins is offline Member
    Join Date
    Sep 2011
    Posts
    6
    Rep Power
    0

    Default Re: Add char

    Help me improve this solution. It is giving error on append.

    Java Code:
    public class ClassC {  
      
        public ClassC() {  
      
            StringBuffer str = new StringBuffer();  
      
            ClasseA a = new ClasseA();  
            char[] d1=a.getPass1().getPassword();  
      
            str.append(d1);  
      
            ClasseB b = new ClasseB();  
            char[] d2=a.getPass2().getPassword();  
      
            str.append(d2);  
      
            ClasseC c = new ClasseC();  
            char[] d3=a.getPass3().getPassword();  
      
            str.append(d3);  
      
            // add d1+d2+d3  
    
     String real = "abc";
    
      //equals ...  real ....
              
      
            System.out.println( str.toString() );  
      
        }  
      
        public static void main(String args[] ) {  
      
            ClassC classC = new ClassC();  
      
        }  
      
    }
    Last edited by analins; 09-22-2011 at 04:44 PM.

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

    Default Re: Add char

    It is giving error on append.
    Please copy and paste here the full text of the error message.

  10. #10
    analins's Avatar
    analins is offline Member
    Join Date
    Sep 2011
    Posts
    6
    Rep Power
    0

    Default Re: Add char

    Error message: <identifier> expected

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

    Default Re: Add char

    Please copy full text of error message and paste it here. Here is a sample:
    Java Code:
    TestSorts.java:138: cannot find symbol
    symbol  : variable var
    location: class TestSorts
             var = 2;
             ^

  12. #12
    analins's Avatar
    analins is offline Member
    Join Date
    Sep 2011
    Posts
    6
    Rep Power
    0

    Default Re: Add char

    The error is displayed when typing the word. append is lined with red.

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

    Default Re: Add char

    Can you compile the program and get an error message from the compiler.
    I don't see any red lines here. What line in the program is the error?

    Post your code and highlight the line that is red lined.

Similar Threads

  1. concatenate two char into one char
    By nadissen in forum Eclipse
    Replies: 3
    Last Post: 04-06-2011, 02:40 PM
  2. Replies: 2
    Last Post: 03-08-2011, 06:20 AM
  3. check a string char by char
    By Sotsiak in forum New To Java
    Replies: 2
    Last Post: 10-23-2010, 09:24 PM
  4. replaceALL(char oldChar, char newChar) method
    By arson09 in forum New To Java
    Replies: 0
    Last Post: 04-28-2010, 05:48 AM
  5. drawing char by char with Graphics
    By diggitydoggz in forum New To Java
    Replies: 5
    Last Post: 12-27-2008, 12:49 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
  •