Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

MyShort.

java

C:\Users\Tommy\Documents\NetBeansProjects\Pratikum\src\MyShort.java 1 import java.util.*; 2 class MyShort 3{ 4 public static void main(String[] args) 5 { 6 //read number from user input 7 System. out .print(" Input : "); 8 Scanner sc=new Scanner(System.in ); 9 10 //read and put Scanner values to array variable 11 char[] temp=sc.nextLine().toCharArray(); 12 int[] num=new int[temp.length]; 13 14 for (int i=0;i<num.length;i++) 15 num[i]=Character.getNumericValue(temp[i]); 16 17 //Call shorting array function 18 bubbleShort (num); 19 20 System. out .print("Output : "); 21 22 for (int i=0;i<num.length;i++) 23 System. out .print(num[i]); 24 25 System. out .println("\n "); 26 checksama (num); 27 28 } 29 30 // function of bubbleShort 31 public static void bubbleShort(int[] arr) 32 { 33 int i,j; 34 i=0; 35 do 36 { 37 for (j=i+1;j<arr.length;j++) 38 { 39 if (arr[i]>arr[j]) 40 { 41 //swap variable 42 swap(arr, i,j); 43 } 44 }i++; 45 }while (i < arr.length); 46 } 47 48 //swap function 49 public static void swap(int[] arr,int i, int j) 50 { 51 int temp;

file:///C|/Users/Tommy/MyShort.html[6/15/2013 2:44:28 PM]

MyShort.java

52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 } 75

temp=arr[i]; arr[i]=arr[j]; arr[j]=temp; } //find duplicate value public static void checksama(int[] arr) { int temp; for (int i=0; i<10; i++) { temp=0; for(int j=0;j<arr.length;j++) { if (i==arr[j]) temp++; } if (temp>1) System. out .println("Number "+ i + " appear " + temp +" times"); } }

file:///C|/Users/Tommy/MyShort.html[6/15/2013 2:44:28 PM]

You might also like