Tuesday, 15 July 2014

Find highest number using if statement in a for loop java -



Find highest number using if statement in a for loop java -

ok little stuck question found online. need write class works out watts resistor goes 1 i.e resistor starts @ 1 , every loop 1 ohm added it: 1 ohm 2 ohm 3 ohm etc etc.

i have done that: there 3 resistors in total , 2 of them have preset ohms. need cycle through 9 times.

i have calculations worked out , getting output it. question gives info , print out. need create print out same.

i have loop working need utilize if statement find highest watts , @ how many ohms resistor had total.

i not asking direct reply problem more point in right direction if @ possible.

in advance give thanks has helped me.

public class question51 { public static void main(string[] args) { double vs = 12, v1, v2, v3, i1, i2, i3, r1 = 10, r2 = 15, r3 = 1, rpar, powerinr3; for(r3 = 1; r3 <= 9; r3++) { rpar = (r2 * r3)/(r2 + r3); i1 = vs/(r1 + rpar); v1 = i1 * r1; v2 = vs - v1; i2 = v2 / r2; i3 = v2 / r3; powerinr3 = v2 * i3; system.out.println("when r3 = "+r3+" ohms, powerfulness in r3 = "+powerinr3+" watts."); } } }

you should declare max variable , initialize low value. illustration double.min_value.

then in every iteration of loop update maximum this:

max = math.max(max, valueyouwanttocompare);

finding right java syntax task :-) luck!

java if-statement for-loop

No comments:

Post a Comment