java - Method to sum 2 numbers and return the value -


so i'm trying finish off java corse in school i'm having problem understanding 1 of tasks.

the task in question is: create method sums 2 numbers , returns sum. methodhead should this; public static double sum(double nr1, double nr2) , problem i'm running in not understand how solve task.

the way of solving task code.

import java.util.scanner;  class addnumbers {     public static void main(string args[]) {         int x, y, z;         system.out.println("enter 2 integers calculate sum ");         scanner in = new scanner(system.in);         x = in.nextint();         y = in.nextint();         z = x + y;         system.out.println("sum of entered integers = "+z);     } } 

but solution i'm not solving task

this may you

import java.util.scanner; class addnumbers {     public static void main(string args[])     {         double x, y, z;         system.out.println("enter 2 numbers calculate sum ");         scanner in = new scanner(system.in);         x = in.nextdouble();         y = in.nextdouble();         z = sum(x,y);         system.out.println("sum of entered numbers = "+z);     }     public static double sum(double nbr1,double nbr2){         return (nbr1+nbr2);     } } 

Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -