Advertisement
Guest User

Untitled

a guest
Nov 10th, 2019
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.05 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class Weaponsmith {
  4.  
  5.     public static void main(String[] args) {
  6.         Scanner scanner = new Scanner(System.in);
  7.  
  8.         String [] parts = scanner.nextLine().split("\\|");
  9.  
  10.         List<String> allparts = new ArrayList<>();
  11.  
  12.         for (int i = 0; i <parts.length ; i++) {
  13.             allparts.add(parts[i]);
  14.         }
  15.  
  16.         String [] command = (scanner.nextLine()).split(" ");
  17.  
  18.         while(!command[0].equals("Done")){
  19.  
  20.             if(command[0].equals("Move")){
  21.  
  22.                 if(command[1].equals("Left")) {
  23.  
  24.                     if(Integer.parseInt(command[2])<allparts.size() && Integer.parseInt(command[2])>0){
  25.                         Collections.swap(allparts,Integer.parseInt(command[2]),Integer.parseInt(command[2])-1);
  26.                     }
  27.                 }
  28.  
  29.                 if(command[1].equals("Right")) {
  30.  
  31.                     if(Integer.parseInt(command[2])<allparts.size()-1 && Integer.parseInt(command[2])>=0){
  32.                         Collections.swap(allparts,Integer.parseInt(command[2]),Integer.parseInt(command[2])+1);
  33.                     }
  34.                 }
  35.             }
  36.  
  37.             if(command[0].equals("Check")) {
  38.  
  39.                 if(command[1].equals("Even")){
  40.  
  41.                     for (int i = 0; i < allparts.size(); i++) {
  42.                         if(i%2==0){
  43.                             System.out.print(allparts.get(i)+ " ");
  44.                         }
  45.                     }
  46.                 }
  47.  
  48.                 if(command[1].equals("Odd")){
  49.  
  50.                     for (int i = 0; i < allparts.size() ; i++) {
  51.                         if(i%2!=0){
  52.                             System.out.print(allparts.get(i)+ " ");
  53.                         }
  54.                     }
  55.  
  56.                 }
  57.             }
  58.             command = (scanner.nextLine()).split(" ");
  59.         }
  60.         System.out.println();
  61.         System.out.print("You crafted ");
  62.         for (String allpart : allparts) {
  63.             System.out.print(allpart);
  64.         }
  65.         System.out.print("!");
  66.  
  67.     }
  68.  
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement