Method / Function Part 2
Mon Apr 19 2021 19:51:23 GMT+0000 (Coordinated Universal Time)
Saved by @ahmedqgqgq #java
import java.util.Scanner; /*write a Java method to find the smallest number among three numbers*/ public class MyName { static int min(int n1, int n2, int n3) { int minNumber = n1; if (minNumber > n2) { minNumber = n2; } if (minNumber > n3) { minNumber = n3; } return minNumber; } public static void main(String[] args) { Scanner input = new Scanner(System.in); int n1 = input.nextInt(); int n2 = input.nextInt(); int n3 = input.nextInt(); System.out.println("minimum number=" + min(n1, n2, n3)); } } import java.util.Scanner; /*write a Java method to find the smallest number among three numbers*/ public class MyName { static int min(int n1, int n2, int n3) { int minNumber = n1; if (minNumber > n2) { minNumber = n2; } if (minNumber > n3) { minNumber = n3; } return minNumber; } public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("Enter #1:"); int n1 = input.nextInt(); System.out.println("Enter #2:"); int n2 = input.nextInt(); System.out.println("Enter #3:"); int n3 = input.nextInt(); System.out.println("minimum number=" + min(n1, n2, n3)); } } import java.util.Scanner; /* Write a Java method to compute the average of three numbers */ public class MyName { static float avg(float n1, float n2, float n3) { float average, sum = n1 + n2 + n3; average = sum / 3; return average; } public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("avg" + avg(100, 99, 98)); } } import java.util.Scanner; /* Write a Java method to compute the average of three numbers */ public class MyName { static float avg(float n1, float n2, float n3) { return (n1 + n2 + n3) / 3; } public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("avg" + avg(100, 99, 98)); } } import java.util.Scanner; /* Write a Java method to compute the average of three numbers */ public class MyName { static float avg(float n1, float n2, float n3) { return (n1 + n2 + n3) / 3; } public static void main(String[] args) { Scanner input = new Scanner(System.in); float ahmed = avg(10, 11, 12); ahmed++; System.out.println(ahmed); } } import java.util.Scanner; public class MyName { public static int sum(int... n) {// int[]n int s = 0; for (int i : n) { s += i; } return s; } public static void main(String[] args) { System.out.println("sum =" + sum(5, 6, 7, 8)); } import java.util.Scanner; public class MyName { public static int sum(int... n) {// int[]n int s = 0; for (int i : n) {//i=n every loop. s += i; } return s; } public static void main(String[] args) { System.out.println("sum =" + sum(5, 6, 7, 8)); } } import java.util.Scanner; public class MyName { public static int sum(int... n) {// int[]n int s = 0; for (int i : n) {//i=n every loop. s += i;//s=s+i; } return s; } public static void main(String[] args) { System.out.println("sum =" + sum(5, 6, 7, 8)); } }
Comments