Advertisement
heysoul_sisypus

Swap sort/bubble algo letter

Feb 6th, 2020
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.96 KB | None | 0 0
  1. package javaapplication114;
  2. import java.util.*;
  3. /**
  4.  *
  5.  * @author Student
  6.  */
  7. public class JavaApplication114 {
  8.  
  9.     /**
  10.      * @param args the command line arguments
  11.      */
  12.     public static void main(String[] args) {
  13.         Scanner scan=new Scanner (System.in);
  14.        
  15.         System.out.println("Swap and Sort Letters");
  16.         System.out.println(" ");
  17.        
  18.         char temp = ' ';
  19.        
  20.         System.out.print("Character 1: ");
  21.         char c1=scan.next().charAt(0);
  22.         System.out.print("Character 2: ");
  23.         char c2=scan.next().charAt(0);
  24.         System.out.print("Character 3: ");
  25.         char c3=scan.next().charAt(0);
  26.         System.out.print("Character 4: ");
  27.         char c4=scan.next().charAt(0);
  28.         System.out.print("Character 5: ");
  29.         char c5=scan.next().charAt(0);
  30.        
  31.         //sort
  32.         if (c2<c1){
  33.         temp=c1;
  34.         c1=c2;
  35.         c2=temp;
  36.         }
  37.         if (c3<c1){
  38.         temp=c1;
  39.         c1=c3;
  40.         c3=temp;
  41.         }
  42.         if (c3<c2){
  43.         temp=c2;
  44.         c2=c3;
  45.         c3=temp;
  46.         }
  47.         if (c4<c1){
  48.         temp=c1;
  49.         c1=c4;
  50.         c4=temp;
  51.         }
  52.         if (c4<c2){
  53.         temp=c2;
  54.         c2=c4;
  55.         c4=temp;
  56.         }
  57.         if (c4<c3){
  58.         temp=c3;
  59.         c3=c4;
  60.         c4=temp;
  61.         }
  62.         //5,4,3,2 and 1
  63.         if (c5<c1){
  64.         temp=c1;
  65.         c1=c5;
  66.         c5=temp;
  67.         }
  68.         if (c5<c2){
  69.         temp=c2;
  70.         c2=c5;
  71.         c5=temp;
  72.         }
  73.         if (c5<c3){
  74.         temp=c3;
  75.         c3=c5;
  76.         c5=temp;
  77.         }
  78.         if (c5<c4){
  79.         temp=c4;
  80.         c4=c5;
  81.         c5=temp;
  82.         }
  83.        
  84.         //output
  85.         System.out.println("Swapped Letters:");
  86.         System.out.println(c1);
  87.         System.out.println(c2);
  88.         System.out.println(c3);
  89.         System.out.println(c4);
  90.         System.out.println(c5);
  91.        
  92.        
  93.     }
  94.    
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement