Dismiss Notice
You are browsing this site as a guest. It takes 2 minutes to CREATE AN ACCOUNT and less than 1 minute to LOGIN

Java code

Discussion in 'Tech, Gadgets & Science Forum' started by mwanamasala, Jul 16, 2012.

  1. m

    mwanamasala JF-Expert Member

    #1
    Jul 16, 2012
    Joined: Jun 20, 2009
    Messages: 248
    Likes Received: 0
    Trophy Points: 0
    public class FishTankVolume
    {
    public static void main(String[] args)
    {
    int width = Integer.parseInt(args[2]);
    int depth = Integer.parseInt(args[4]);
    int height = Integer.parseInt(args[6]);
    int volume = width * depth * height;
    System.out.println("The volume of a tank with dimensions"
    + "(" + width + "," + depth + "," + height + ") "
    + "is " + volume);
    }


    }
    I tried to run this code using Eclipse IDE without success!Jibu linatakiwa liwe 48.
    Kuna makosa gani kwenye hiyo code?
     
  2. Mchizi

    Mchizi JF-Expert Member

    #2
    Jul 16, 2012
    Joined: Apr 23, 2009
    Messages: 304
    Likes Received: 97
    Trophy Points: 45
    Kama unahitaji jibu liwe 48 then ondoa arguments

    public class FishTankVolume
    {
    public static void main(String[] args)
    {
    int width = Integer.parseInt("2");
    int depth = Integer.parseInt("4");
    int height = Integer.parseInt("6");
    int volume = width * depth * height;
    System.out.println("The volume of a tank with dimensions"
    + "(" + width + "," + depth + "," + height + ") "
    + "is " + volume);
    }


    }
     
  3. Kang

    Kang JF-Expert Member

    #3
    Jul 16, 2012
    Joined: Jun 24, 2008
    Messages: 4,699
    Likes Received: 204
    Trophy Points: 160
    Hiyo args ni array ya arguments ulizoziandika wakati unairun program yako kutoka command line so unaposema args[6] itaenda kuchukua argument ya saba uliyoandika wakati unarun program So ukirun program hivi
    java FishTankVolume 23 44 13 67 12 34 78 43

    itachukua 13,12 na 78
     
  4. L

    Leney JF-Expert Member

    #4
    Jul 18, 2012
    Joined: Jul 9, 2007
    Messages: 315
    Likes Received: 1
    Trophy Points: 0
    you only use arguments if you want a user to enter the width, depth and height from the keyboard, otherwise you need to hard code the numbers just like the way mchizi has done.
     
Loading...