Results 1 to 5 of 5

Thread: conversion

  1. #1
    Dayanand is offline Member
    Join Date
    Feb 2011
    Posts
    61
    Rep Power
    0

    Default conversion

    package conversion;

    public class Mgr4
    {
    public static void main(String[] args)
    {
    String s1 = String.format("sum of %d,%d is"+10,20,[10+20]);
    }
    }


    can any one tell why the statement--String s1 = String.format("sum of %d,%d is"+10,20,[10+20]); results compilation error

    Thanks in advance
    Daya

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,372
    Blog Entries
    7
    Rep Power
    25

    Default

    Quote Originally Posted by Dayanand View Post
    can any one tell why the statement--String s1 = String.format("sum of %d,%d is"+10,20,[10+20]); results compilation error
    Remove those square brackets, they are used for array indexes and don't make any sense here.

    kind regards,

    Jos
    The only person who got everything done by Friday was Robinson Crusoe.

  3. #3
    rp181 is offline Member
    Join Date
    Mar 2009
    Posts
    70
    Rep Power
    0

    Default

    don;t really use format in java, but you are printing 3 ints (%i, %d works). You have 2.

    Try:

    Java Code:
    String.format("sum of %i,%i is %i",10,20,(10+20));

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,067
    Rep Power
    23

    Default

    What compilation error do you get?

    ETA: Oh come on. Don't let him get away with sloppy questions like that!
    For shame!
    ;)

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,372
    Blog Entries
    7
    Rep Power
    25

    Default

    Quote Originally Posted by Tolls View Post
    What compilation error do you get?

    ETA: Oh come on. Don't let him get away with sloppy questions like that!
    For shame!
    ;)
    I personally found this question reasonable compared to the crap where they dump pages and pages of unreadable code at us with a single "urgent, this doesn't work! Send me teh codez for dis script! plzzzzzz! The deadline if on Friday!"

    kind regards,

    Jos ;-)
    The only person who got everything done by Friday was Robinson Crusoe.

Similar Threads

  1. XLS to PDF conversion
    By nitin2k2k in forum Advanced Java
    Replies: 18
    Last Post: 07-02-2013, 11:17 AM
  2. String to Hex Conversion
    By mocha in forum New To Java
    Replies: 0
    Last Post: 03-17-2010, 09:45 AM
  3. Type conversion
    By hannes in forum New To Java
    Replies: 2
    Last Post: 12-18-2009, 12:29 PM
  4. Doc to Pdf conversion
    By praveen.kb in forum Advanced Java
    Replies: 2
    Last Post: 01-16-2009, 01:27 PM
  5. Conversion from wav to vox
    By bozovilla in forum Advanced Java
    Replies: 1
    Last Post: 07-31-2008, 05:54 AM

Posting Permissions

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