Basic Java and Eclipse -


make util class 3 methods. first method's name add, returns result adding 2 numbers.

second method's name multiply, returns result multiplying 2 numbers.

third's method name division returns result dividing first parameter second parameter.

then call method class called main , print results 6 times each method call? i'm having trouble part.

this i've got far:

public class util {     public static int add(int a, int b) {         int result = + b;         system.out.println("result = " + result);          return result;     }      public static int multiply(int a, int b) {         int result = * b;         system.out.println("result = " + result);          return result;     }      public static int divide(int a, int b) {         int result = / b;         system.out.println("result = " + result);          return result;     }      public static void main(string[] args) {         int res = multiply(5, 2);         system.out.println("res = " + res);          res = add(5, 2);         system.out.println("res = " + res);          res = divide(5, 2);         system.out.println("res = " + res);     } }     

how this: call method class called main , print results 6 times each method call?

just use loop that:

public static void main(string[] args) {     (int = 0; <= 6; i++) {         system.out.println(multiply(5, 2));         system.out.println(add(5, 2));         system.out.println(divide(5, 2));     } } 

or class:

public class main() {  private util myutil;  public void calculate() {      (int = 0; <= 6; i++) {         system.out.println(myutil.multiply(5, 2));         system.out.println(myutil.add(5, 2));         system.out.println(myutil.divide(5, 2));     }  }      public static void main(string[] args) {     main mymain = new main();     mymain.calculate(); } 

Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -