SHARE
TWEET

Untitled

a guest Mar 24th, 2019 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2.  
  3. public class HW1_Sort {
  4.  
  5.     public static void main(String[] args) {
  6.         int arr[];
  7.         int num;
  8.         int i;
  9.         Scanner scan = new Scanner(System.in); //์ž…๋ ฅ ํด๋ž˜์Šค ์ƒ์„ฑ
  10.         System.out.print("n ๊ฐ’ ์ž…๋ ฅ : ");
  11.         num = scan.nextInt(); //์ˆซ์ž์˜ ๊ฐœ์ˆ˜๋ฅผ ์„ค์ •
  12.         arr = new int[num]; // ์ž…๋ ฅ๋ฐ›์€ ๊ฐฏ์ˆ˜๋กœ ๋ฐฐ์—ด์˜ ํฌ๊ธฐ๋ฅผ ์„ค์ •
  13.         System.out.print("์ˆซ์ž "+ num +"๊ฐœ๋ฅผ ์ž…๋ ฅํ•˜์‹œ์˜ค : ");
  14.         for(i=0; i<num; i++) //๋ฌด์ž‘์œ„ ์ˆซ์ž๋ฅผ ์ž…๋ ฅ
  15.             arr[i] = scan.nextInt();
  16.         sort(arr); //sortํ•จ์ˆ˜๋ฅผ ์‹คํ–‰ํ•ด ์˜ค๋ฆ„์ฐจ์ˆœ์œผ๋กœ ์ •๋ ฌ
  17.         System.out.print("์ •๋ ฌ๊ฒฐ๊ณผ : ");
  18.         for(i=0; i<arr.length; i++) //์ •๋ ฌ ๊ฒฐ๊ณผ๋ฅผ ์ˆœ์„œ๋Œ€๋กœ ์ถœ๋ ฅ
  19.             System.out.print(arr[i] + " ");
  20.     }
  21.     public static void sort(int arr[]) { //๋ฐฐ์—ด์„ ๋ฐ›์•„ ์˜ค๋ฆ„์ฐจ์ˆœ์œผ๋กœ ์ •๋ ฌํ•˜๋Š” ํ•จ์ˆ˜
  22.         int i,j;
  23.         int temp;
  24.         for(i=0; i<arr.length; i++){
  25.             for(j=0; j<arr.length; j++) {
  26.                 if(arr[i]<arr[j]) {
  27.                     temp = arr[i];
  28.                     arr[i] = arr[j];
  29.                     arr[j] = temp;
  30.                 }
  31.             }
  32.         }
  33.     }
  34. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top