أكتب برنامج يحتوي على Method يطلب من المستخدم إدخال 3 أرقام و من ثم يطبع الرقم الاصغر.
الحل
الحل
import java.util.Scanner;
public class SmallNum {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter 1st number: ");
int a = input.nextInt();
System.out.println("Enter 2nd number: ");
int b = input.nextInt();
System.out.println("Enter 3rd number: ");
int c = input.nextInt();
System.out.println("Smallest number is " + SmallNumM(a,b,c));
}
public static int SmallNumM(int x,int y,int z) {
if (x<y && x<z)
return x;
else if (y<z)
return y;
else
return z;
}
}
public class SmallNum {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter 1st number: ");
int a = input.nextInt();
System.out.println("Enter 2nd number: ");
int b = input.nextInt();
System.out.println("Enter 3rd number: ");
int c = input.nextInt();
System.out.println("Smallest number is " + SmallNumM(a,b,c));
}
public static int SmallNumM(int x,int y,int z) {
if (x<y && x<z)
return x;
else if (y<z)
return y;
else
return z;
}
}