Results 1 to 2 of 2
  1. #1
    BillyB is offline Member
    Join Date
    Nov 2010
    Posts
    22
    Rep Power
    0

    Default Print variable data type

    I imagine there is a way to display the data type of a variable but I haven't been able to find it. For example:

    int a = 10;
    int b = a/2.2;
    System.out.println("The data type of b is ???: ")

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Your code won't compile with the line:
    Java Code:
    int b = 1/2.2;

    Regarding your question, you can use reflection to get the data types of a class's fields, but I don't think it will work for variables inside of a method or other block.

Similar Threads

  1. do while (variable != type)
    By Romally in forum New To Java
    Replies: 2
    Last Post: 11-15-2010, 05:29 AM
  2. Print Variable From One Class to Output on another.
    By Lyricid in forum New To Java
    Replies: 8
    Last Post: 02-27-2010, 01:56 PM
  3. Replies: 1
    Last Post: 12-09-2009, 12:57 AM
  4. print variable with paint(Graphics g) ??
    By tghn2b in forum New To Java
    Replies: 10
    Last Post: 12-29-2008, 12:11 PM
  5. [SOLVED] curiosity about String type variable
    By monir6464 in forum Advanced Java
    Replies: 1
    Last Post: 04-08-2008, 11:13 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
  •