Skip to content

Instantly share code, notes, and snippets.

@hyperion0201
Last active September 5, 2017 07:03
Show Gist options
  • Save hyperion0201/aaeaeb1bdd511d79149a7738850094e0 to your computer and use it in GitHub Desktop.
Save hyperion0201/aaeaeb1bdd511d79149a7738850094e0 to your computer and use it in GitHub Desktop.
JAVA Algorithm find Min, Max merge from 2 num <100.
// Chuong trinh tim so lon nhat va so be nhat tao thanh tu 2 so nguyen 2 chu so
import javax.swing.*;
import java.util.*;
class MinMax {
public static void swapFunction(int[] a, int n) { // Initialising the Array Swapping Function
for (int i = 0; i < n; i++) {
for (int j = (i+1); j < n; j++) {
if (a[i] > a[j]) {
int temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
}
}
public static void main(String[] args) { // Go to Main
JFrame myFrame = new JFrame(); // Create the frame
myFrame.setSize(500, 300);
myFrame.setTitle("Tinh Min Max");
myFrame.setVisible(true);
String str1 = JOptionPane.showInputDialog(myFrame,"Nhap vao so a = ");
int a = Integer.parseInt(str1);
String str2 = JOptionPane.showInputDialog(myFrame,"Nhap vao so b = ");
int b = Integer.parseInt(str2);
int x = a/10;
int y = a%10;
int j = b/10;
int k = b%10;
int[] list = {x, y, j, k};
swapFunction(list, list.length); // Swap the array "list" use swapFunction called
int Min = list[0]*1000 + list[1]*100 + list[2]*10 + list[3];
int Max = list[3]*1000 + list[2]*100 + list[1]*10 + list[0];
JOptionPane.showMessageDialog(myFrame, "So be nhat duoc tao thanh la : " + Min + "\n" + "So lon nhat duoc tao thanh la : " + Max);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment