Results 1 to 9 of 9
  1. #1
    happy12 is offline Member
    Join Date
    Sep 2013
    Posts
    2
    Rep Power
    0

    Default For loop datatype

    This was an interview question that was asked to me:

    Can we have other datatype in forloop: for eg

    for(int i=0;i<10;i++)

    instead can we write

    for(short i=0;i<10;i++)


    can we use short or any other datatype instead of integer? If we can use other datatypes why do we keep on using integer?
    Also he said suppose we just want to use numbers from 0 to 10....than why do we need integer? and not short?
    That was the question

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,685
    Rep Power
    8

    Default Re: For loop datatype

    And what was your answer? What happened when you wrote a little test program? What have you tried? What are you confused about?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    jbarke12 is offline Member
    Join Date
    May 2013
    Location
    Charleston, South Carolina USA
    Posts
    78
    Rep Power
    0

    Default Re: For loop datatype

    This is a great question to make sure you understand the underlying architectures. Try it and see. If it does work for both why do you think we use integers?

  4. #4
    happy12 is offline Member
    Join Date
    Sep 2013
    Posts
    2
    Rep Power
    0

    Default Re: For loop datatype

    If you don't want to answer, don't reply and eat brain. Simple.
    Go to someone else posting and reply there.

    F* thanks for ur help.

  5. #5
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    United States
    Posts
    2,923
    Rep Power
    4

    Default Re: For loop datatype

    Quote Originally Posted by jbarke12 View Post
    If it does work for both why do you think we use integers?
    Because int is easier to type than byte or short.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default Re: For loop datatype

    Quote Originally Posted by happy12 View Post
    If you don't want to answer, don't reply and eat brain. Simple.
    Go to someone else posting and reply there.

    F* thanks for ur help.
    You deserve to be banned.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  7. #7
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    12,995
    Blog Entries
    7
    Rep Power
    19

    Default Re: For loop datatype

    Quote Originally Posted by happy12 View Post
    If you don't want to answer, don't reply and eat brain. Simple.
    Go to someone else posting and reply there.

    F* thanks for ur help.
    Change your attitude; the replies were perfectly valid. Don't do this again or you'll be banned.

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  8. #8
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,047
    Rep Power
    4

    Default Re: For loop datatype

    Quote Originally Posted by JosAH View Post
    Change your attitude; the replies were perfectly valid. Don't do this again or you'll be banned.

    Jos
    An apology to JBarke12 would first be in order I'd say, or otherwise I see little help for this sad individual in the future.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  9. #9
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,685
    Rep Power
    8

    Default Re: For loop datatype

    Quote Originally Posted by happy12 View Post
    If you don't want to answer, don't reply and eat brain. Simple.
    Go to someone else posting and reply there.
    Will do. Good luck learning programming or getting a job with that attitude.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. datatype: double
    By JavaJimme in forum New To Java
    Replies: 1
    Last Post: 06-05-2013, 12:44 PM
  2. JList raw datatype ...?
    By hreodbeohrt in forum New To Java
    Replies: 3
    Last Post: 11-05-2011, 04:25 AM
  3. Datatype of a class?
    By Skipito in forum NetBeans
    Replies: 5
    Last Post: 10-12-2011, 07:04 PM
  4. char datatype
    By frejon26 in forum New To Java
    Replies: 5
    Last Post: 05-04-2010, 11:21 PM
  5. how to find a datatype
    By hasysf in forum New To Java
    Replies: 1
    Last Post: 09-06-2009, 10:41 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
  •