Java code

mwanamasala

JF-Expert Member
Jun 20, 2009
248
12
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?
 
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?

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);
}


}
 
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
 
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?

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.
 
0 Reactions
Reply
Back
Top Bottom