Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package javaapplication114;
- import java.util.*;
- /**
- *
- * @author Student
- */
- public class JavaApplication114 {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- Scanner scan=new Scanner (System.in);
- System.out.println("Swap and Sort Letters");
- System.out.println(" ");
- char temp = ' ';
- System.out.print("Character 1: ");
- char c1=scan.next().charAt(0);
- System.out.print("Character 2: ");
- char c2=scan.next().charAt(0);
- System.out.print("Character 3: ");
- char c3=scan.next().charAt(0);
- System.out.print("Character 4: ");
- char c4=scan.next().charAt(0);
- System.out.print("Character 5: ");
- char c5=scan.next().charAt(0);
- //sort
- if (c2<c1){
- temp=c1;
- c1=c2;
- c2=temp;
- }
- if (c3<c1){
- temp=c1;
- c1=c3;
- c3=temp;
- }
- if (c3<c2){
- temp=c2;
- c2=c3;
- c3=temp;
- }
- if (c4<c1){
- temp=c1;
- c1=c4;
- c4=temp;
- }
- if (c4<c2){
- temp=c2;
- c2=c4;
- c4=temp;
- }
- if (c4<c3){
- temp=c3;
- c3=c4;
- c4=temp;
- }
- //5,4,3,2 and 1
- if (c5<c1){
- temp=c1;
- c1=c5;
- c5=temp;
- }
- if (c5<c2){
- temp=c2;
- c2=c5;
- c5=temp;
- }
- if (c5<c3){
- temp=c3;
- c3=c5;
- c5=temp;
- }
- if (c5<c4){
- temp=c4;
- c4=c5;
- c5=temp;
- }
- //output
- System.out.println("Swapped Letters:");
- System.out.println(c1);
- System.out.println(c2);
- System.out.println(c3);
- System.out.println(c4);
- System.out.println(c5);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement