Java: viết phương trình tính max/min 4 số nhập vào từ bàn phím Làm kiểu java nha mọi người
2 câu trả lời
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int max, min;
System.out.println();
int a = scanner.nextInt();
System.out.println();
int b = scanner.nextInt();
System.out.println();
int c = scanner.nextInt();
System.out.println();
int d = scanner.nextInt();
max = a; min= a;
if (max < b) max= b;
if(max < c) max= c;
if(max < d ) max= d;
if(b < min) min= b;
if(c < min) min= c;
if(d < min) min= d;
System.out.println("" + max);
System.out.println(""+ min);
}
}
`* Java:`
`" "`
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
System.out.print("Nhap 4 so: ");
Scanner saisir = new Scanner (System.in);
double pre = saisir.nextDouble();
double deu = saisir.nextDouble();
double troi = saisir.nextDouble();
double quan = saisir.nextDouble();
double grand = pre;
if (deu > grand)
grand = deu;
if (troi > grand)
grand = troi;
if (quan > grand)
grand = quan;
double pet = pre;
if (deu < pet)
pet = deu;
if (troi < pet)
pet = deu;
if (quan < pet)
pet = quan;
System.out.println("So lon nhat = " + grand);
System.out.println("So nho nhat = " + pet);
}
}