Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   Java (https://www.askmehelpdesk.com/forumdisplay.php?f=440)
-   -   On primitives (https://www.askmehelpdesk.com/showthread.php?t=817617)

  • Oct 28, 2015, 06:52 AM
    kiruthikalakha
    On primitives
    public static void main(String[] args) {
    // TODO code application logic here
    char a='H';
    int b=3110;
    String c="WOR";
    int d=1;
    char e ='d';
    double f=2.0;
    boolean g=true;
    String s =a+b+c+d+e+f+g;
    System.out.println(s);
    }


    I want to display H3110WOR1d2.0true
    but the o/p displayed is 3182WOR1d2.0true.

    Why and how to correct it??
  • Oct 28, 2015, 07:45 AM
    CravenMorhead
    First off, look at the ascii code value for H. I will give you a hint. It is 72 decimal. Char are often used as single byte numerical values so the initial two terms is being treating as an addition instead of appending. So what you need to do is figure out how to do the string addition you're doing without causing summation but rather appending.

  • All times are GMT -7. The time now is 02:03 PM.