Java Methods | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
+ 1

Java Methods

I need to declare a method that returns double values and takes int as a parameter. e.g. static double result(int x, int y){ return x/y } for example if I put 5 and 2 as x and y, will 2.5 be returned?

2nd Jan 2018, 11:31 AM
Sad - avatar
2 ответов
+ 21
public class Program{ public static void main(String[] args){ double a=result(5,2); //method call System.out.print(a); } static double result(int x,int y){ //method definition return (double)x/y; } } //hope it helps☺
2nd Jan 2018, 11:41 AM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 1
Thanks it helped😊👍
2nd Jan 2018, 11:43 AM
Sad - avatar