Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Primitive data type

  1. #1
    Junior Member
    Join Date
    Sep 2011
    Location
    London
    Posts
    2
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post Primitive data type

    Hey guys i'm new at all this and this question i'm about to ask sounds really silly, but any help would be great, Iv'e been giving this assignment but i'm stuck on the last segment of code I also have to print a line of somthing the trouble is i'm not really 100%i know what this programme is doing thanks.
    public class DataTypeDemo    
    {   
        public static void main (String [] args)   
        {   
            int  x = 10;   
            double d;   
            d = x;   
     
            double y;   
            y = d;   
            y = (int) d;   
     
     
            float z;   
            z = (int) 3.14;   
            z = 3.14F;   
     
            long id;   
            id = 43251234153313241;   
            id = 43251234153313241L;   
     
            byte a, b, c;   
            a = 10;   
            b = 5;   
            c = (byte) (a + b);   
            c = (byte) (a + b);   
     
            String name = "rich";   
            x =  name;   
            x = (int) name;   
     
        }      
    }
    Last edited by helloworld922; September 17th, 2011 at 12:12 PM.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Primitive data type

    Please explain what the problem is. If there are error messages, copy and paste them here.

  3. #3
    Junior Member
    Join Date
    Sep 2011
    Location
    London
    Posts
    2
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Primitive data type

    oh i thought i did. The problem is the last segment of code i know you can't convert string to int but that was the problem i was given thanks

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Primitive data type

    convert string to int
    Look at the Integer class. It has a method for converting a String to an int

  5. #5
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Primitive data type

    There is no integer equivalent for "rich". Could you please post the question posed by the assignment?

Similar Threads

  1. Tutorial: Primitive Data Types
    By newbie in forum Java Programming Tutorials
    Replies: 3
    Last Post: July 5th, 2012, 11:56 PM
  2. [SOLVED] cannot referenced <instance data member> before super type constructr has been called
    By chronoz13 in forum What's Wrong With My Code?
    Replies: 14
    Last Post: August 8th, 2011, 11:26 AM
  3. Need something like a "Hashtable<String[], Integer>" kind of data type @@
    By Albretch Mueller in forum Java Theory & Questions
    Replies: 2
    Last Post: November 27th, 2010, 10:24 PM
  4. About heap data type
    By PaddyWangTheGG in forum Algorithms & Recursion
    Replies: 2
    Last Post: May 17th, 2010, 03:02 PM
  5. Selection Sorting of Data type (Char)
    By chronoz13 in forum Algorithms & Recursion
    Replies: 1
    Last Post: December 20th, 2009, 08:28 PM

Tags for this Thread