Results 1 to 2 of 2

Thread: Byte class ?

  1. #1
    Hardik is offline Member
    Join Date
    Jul 2009
    Posts
    6
    Rep Power
    0

    Question Byte class ?

    class Demo
    {
    public static void main(String[] args)
    {
    int a;
    byte b;
    a = Integer.parseInt(args[0]);
    b = Byte.parse.Byte(args[1]);
    System.out.println("Result = "+(a*b));
    }
    }


    -->In 8 th line there i have used Byte class that is correct ? If not then what
    will be the code for this .

  2. #2
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    843
    Rep Power
    6

    Default

    Hi,
    Gothru Sun tutorial before writing the code.
    Write comments what u want to acheive then ask doubts.See the corrected code below.Here Byte is class which is having parseByte method to convert the String arg to Byte arg.


    Java Code:
    class Demo
    {
    public static void main(String[] args)
    {
    int a;
    byte b;
    //Got the String value and converted to int  
    a = Integer.parseInt(args[0]);
    //Got the String value and converted to byte
    b = Byte.parseByte(args[1]);
    
    //Multiplied and displayed
    
    System.out.println("Result = "+(a*b));
    }
    }
    Ramya:cool:

Similar Threads

  1. TCP send byte
    By Koren3 in forum Networking
    Replies: 4
    Last Post: 05-25-2009, 08:08 AM
  2. Byte Array
    By sandor in forum New To Java
    Replies: 12
    Last Post: 01-15-2009, 04:31 AM
  3. using Byte arrays
    By mew in forum New To Java
    Replies: 2
    Last Post: 01-30-2008, 04:54 AM
  4. int to byte
    By ravian in forum New To Java
    Replies: 1
    Last Post: 01-13-2008, 08:22 PM

Posting Permissions

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