Results 1 to 16 of 16
  1. #1
    ran830421 is offline Member
    Join Date
    Nov 2009
    Posts
    7
    Rep Power
    0

    Question how to know the input value of integer

    i am ran
    my query is how to know the input value of integer is decimal or hexdecimal

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Input from where?

  3. #3
    ran830421 is offline Member
    Join Date
    Nov 2009
    Posts
    7
    Rep Power
    0

    Exclamation i will explain

    for ex consider integer variables a,b
    a='0x5a';
    b=90;
    here both are displays same values when print them
    i want know the input of a is decimal or hexdecimal. input value is given by others it will not displays to the programer

  4. #4
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    With those quotes it won't compile at all.
    If you remove the quotes then hexadecimals start with 0x or 0X.

  5. #5
    mrmatt1111's Avatar
    mrmatt1111 is offline Senior Member
    Join Date
    Aug 2009
    Location
    San Jose, CA, USA
    Posts
    320
    Rep Power
    6

    Default

    Both values get stored in the same form (4 bytes for integer; base 16) and represented as an integer when you display it on the screen or in your code (not a decimal number!).

    Java Code:
    int a = 0xF3;
    int b = 243;
    
    System.out.println(a);
    if(a == b)
       System.out.println("Equivalant!");
    if(0x000000F3 == 243)
       System.out.println("Equivalant!");
    Last edited by mrmatt1111; 11-18-2009 at 07:51 PM.
    My Hobby Project: LegacyClone

  6. #6
    ran830421 is offline Member
    Join Date
    Nov 2009
    Posts
    7
    Rep Power
    0

    Default

    my problem is that input is given by other programmer it is decimal or hexdecimal value .
    i want to know that the given input value is decimal or hexdecimal. based on this i can solve the puzzle.
    for ex he gives the input for integer variable is 0x5a it is hexdecimal value then i will divide it by rgb format and solve the puzzle.
    if it is decimal it will be solved by another way

  7. #7
    mrmatt1111's Avatar
    mrmatt1111 is offline Senior Member
    Join Date
    Aug 2009
    Location
    San Jose, CA, USA
    Posts
    320
    Rep Power
    6

    Default

    as r035198x asked "Input from where?"

    If you input is the form of a string you can do something like this:

    Java Code:
    int value = 0;
    try
    {
       value = Integer.parseInt(input); //input is a string
    }
    catch(Exception e)
    {
       System.out.println("Not an Integer")
    }
    Last edited by mrmatt1111; 11-18-2009 at 07:59 PM.
    My Hobby Project: LegacyClone

  8. #8
    ran830421 is offline Member
    Join Date
    Nov 2009
    Posts
    7
    Rep Power
    0

    Default

    i will explain clearly



    package test.blurimg;

    public class BlurImage {


    public image blur_image(image i, int radius) {
    //Write your code here

    return null;
    }
    // You could use this sample code to test your functions
    // Following main fucntion contains 3 representative test cases
    public static void main(String[] args) {
    //TestCase 1
    try {
    image i = new image();
    i.rows = 5;
    i.columns = 3;
    i.data = new int[][]{{6, 12, 18}, {5, 11, 17}, {4, 10, 16}, {3, 9, 15}, {2, 8, 14}};

    BlurImage obj = new BlurImage();
    image res = obj.blur_image(i, 2);
    System.out.println("TestCase 1");
    if (res != null) {
    for (int k = 0; k < i.rows; k++) {
    System.out.println();
    for (int j = 0; j < i.columns; j++) {
    System.out.print(res.data[k][j] + ",");
    }
    }
    } else
    System.out.println("NULL");
    }
    catch (Exception e) {
    e.printStackTrace();
    }
    //TestCase 2
    try {
    image i = new image();
    i.rows = 3;
    i.columns = 5;
    i.data = new int[][]{{0x5a0060, 0x6a0050, 0x6a0050, 0x6a0050, 0x7f0038},
    {0x5a0060, 0x6a0050, 0x6a0050, 0x6a0050, 0x7f0038},
    {0x5a0060, 0x6a0050, 0x6a0050, 0x6a0050, 0x7f0038}};

    BlurImage obj = new BlurImage();
    image res = obj.blur_image(i, 1);
    System.out.println("\nTestCase 2");
    if (res != null) {
    for (int k = 0; k < i.rows; k++) {
    System.out.println();
    for (int j = 0; j < i.columns; j++) {
    System.out.print(res.data[k][j] + ",");
    }
    }
    } else
    System.out.println("NULL");
    }
    catch (Exception e) {
    e.printStackTrace();
    }
    //TestCase 3
    try {
    image i = new image();
    i.rows = 3;
    i.columns = 5;
    i.data = new int[][]{{0x5a0060, 0x6a0050, 0x6a0050, 0x6a0050, 0x7f0038},
    {0x5a0060, 0x6a0050, 0x6a0050, 0x6a0050, 0x7f0038},
    {0x5a0060, 0x6a0050, 0x6a0050, 0x6a0050, 0x7f0038}};

    BlurImage obj = new BlurImage();
    image res = obj.blur_image(i, 4);
    System.out.println("\nTestCase 3");
    if (res != null) {
    for (int k = 0; k < i.rows; k++) {
    System.out.println();
    for (int j = 0; j < i.columns; j++) {
    System.out.print(res.data[k][j] + ",");
    }
    }
    } else
    System.out.println("NULL");
    }
    catch (Exception e) {
    e.printStackTrace();
    }
    }
    }

    this is my puzzle here i.data is input it contains both decimal and hexdecimal values
    if i.data contains hexdecimal value it will converted into RGB format and solved.
    otherwise i will solve by another way.

  9. #9
    mrmatt1111's Avatar
    mrmatt1111 is offline Senior Member
    Join Date
    Aug 2009
    Location
    San Jose, CA, USA
    Posts
    320
    Rep Power
    6

    Default

    You have to understand, whether you represent your value as a hexdecimal or an integer, it's real value is exactly the same. There is no way to know the difference because there is no difference.
    My Hobby Project: LegacyClone

  10. #10
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Where is the array data coming from?
    Do you read it from a file? Do you receive it as an object or perhaps strings passed as program arguments?
    This is the question that we have been asking and you have not answered.

  11. #11
    ran830421 is offline Member
    Join Date
    Nov 2009
    Posts
    7
    Rep Power
    0

    Default

    if array contains hexdecimal value then it will in the form of RGB now i will divide it R,G,B and find the avg of r,g,b of surrounded values for a value.
    if it is decimal i will find the avg of surrounded values for a value.

    here i need to find out if array contains hexdecimal it will follow first case other wise second case

    the solution for this puzzle will suitable for all input values like decimal and hexdecimal

  12. #12
    ran830421 is offline Member
    Join Date
    Nov 2009
    Posts
    7
    Rep Power
    0

    Default

    here data is array of integers. they cannot allow using of strings.
    we must follow the rules.
    here we are using the given inputs only. i already posted them along with puzzle.

    please refer them .

    package test.blurimg;


    public class image {
    public int[][] data;
    public int rows;
    public int columns;
    }

  13. #13
    xcallmejudasx's Avatar
    xcallmejudasx is offline Senior Member
    Join Date
    Oct 2008
    Location
    Houston, TX & Flint, MI
    Posts
    609
    Rep Power
    6

    Default

    Convert your input to a string and check with the subString method if it contains an 'x' or any letters 'a-f'
    Liberty has never come from the government.
    Liberty has always come from the subjects of government.
    The history of liberty is the history of resistance.
    The history of liberty is a history of the limitation of governmental power, not the increase of it.

  14. #14
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Then integers are just integers.
    The values are the same.
    This has already been said before but you continue to ignore it.

  15. #15
    ran830421 is offline Member
    Join Date
    Nov 2009
    Posts
    7
    Rep Power
    0

    Default

    in my puzzle i am passing the object to a function . object contains array of integers .
    once when i assign a hexdecimal value to integer it will convert into binary format.
    when i was trying to convert it into string it will gives a decimal value even if we are assign the hexdecimal values. "we cannot change the inputs. it is rule for this contest"

  16. #16
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Are we also allowed to read responses posted to this thread?


    Why do you post at all if you ignore the responses that you get?

Similar Threads

  1. How to convert Integer[] to int[]
    By Nithya in forum New To Java
    Replies: 26
    Last Post: 02-11-2010, 05:41 PM
  2. Input technique for unknown lines of input
    By ducreative in forum New To Java
    Replies: 16
    Last Post: 09-23-2009, 09:26 AM
  3. input to an integer (simply)
    By chitwood in forum Advanced Java
    Replies: 3
    Last Post: 03-18-2009, 06:34 AM
  4. Integer vs int
    By bugger in forum New To Java
    Replies: 1
    Last Post: 11-14-2007, 09:13 PM
  5. how to take input and verify input in Java programs
    By bilal_ali_java in forum Advanced Java
    Replies: 0
    Last Post: 07-21-2007, 08:46 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
  •