title: How to convert an input of 3 octal numbers into CHMOD permissions into Binary?
body: <p>I am trying to create a program that takes input from the user using the command line of 3 octal number, for example 5, 2, 6 or 5,2,6 and convert them into 3 sets of 3 digit binary numbers, like 101 010 110, and also print out those corresponding CHMOD permissions like r-x -w- rw-.</p>
  
  <p>I am having a lot of trouble splicing these numbers apart with substring into 3 separate numbers of 5 2 and 6.</p>
  
  <p>I also need the program to convert from the set of binary digits into 3 numerical digits and permissions.  And from the permissions into digits and binary.</p>
  
  <p>Here is what I have so far:</p>
  
  <pre><code>import java.util.Scanner;
  class Test {
          public static void main(String cheese[]){
  
              Scanner scan = new Scanner(System.in);
  
              String line1 = scan.nextLine();
              //String line2 = scan.nextLine();
              //String line3 = scan.nextLine();
              //String line4 = scan.nextLine();
              //String line5 = scan.nextLine();
  
              System.out.println(line12(line1));
  
  
          }
  
          public static String line12(String line){
              String ownerPermissions = "";
              String groupPermissions = "";
              String otherPermissions = "";
  
              int comma = 0;
  
              int lineLength = line.length();
  
              if (line.indexOf(" ") != -1){
                  comma = line.indexOf(",");
              }else{
                  comma = 1;
              }
  
              String firstNumber = line.substring(0, 1);
  
              line = line.substring(comma + 1, lineLength);
  
              int comma2 = line.indexOf(",");
              String secondNumber = line.substring(comma + 1, comma2);
  
              String thirdNumber = line.substring(lineLength);
  
              int firstInt= Integer.parseInt(firstNumber);
              int secondInt = Integer.parseInt(secondNumber);
              int thirdInt = Integer.parseInt(thirdNumber);
  
              String firstBinary = Integer.toBinaryString(firstInt);
              String secondBinary = Integer.toBinaryString(secondInt);
              String thirdBinary = Integer.toBinaryString(thirdInt);
  
              switch(firstInt){
  
                  case 0:
                      ownerPermissions = "---";
                      break;
                  case 1:
                      ownerPermissions = "--x";
                      break;
                  case 2:
                      ownerPermissions = "-w-";
                      break;
                  case 3:
                      ownerPermissions = "-wx";
                      break;
                  case 4:
                      ownerPermissions = "r--";
                      break;
                  case 5:
                      ownerPermissions = "r-x";
                      break;
                  case 6:
                      ownerPermissions = "rw-";
                      break;
                  case 7:
                      ownerPermissions = "rwx";
                      break;
              }
  
              switch(secondInt){
  
                  case 0:
                      groupPermissions = "---";
                      break;
                  case 1:
                      groupPermissions = "--x";
                      break;
                  case 2:
                      groupPermissions = "-w-";
                      break;
                  case 3:
                      groupPermissions = "-wx";
                      break;
                  case 4:
                      groupPermissions = "r--";
                      break;
                  case 5:
                      groupPermissions = "r-x";
                      break;
                  case 6:
                      groupPermissions = "rw-";
                      break;
                  case 7:
                      groupPermissions = "rwx";
                      break;
              }
  
              switch(thirdInt){
  
                  case 0:
                      otherPermissions = "---";
                      break;
                  case 1:
                      otherPermissions = "--x";
                      break;
                  case 2:
                       otherPermissions = "-w-";
                      break;
                  case 3:
                      otherPermissions = "-wx";
                      break;
                  case 4:
                      otherPermissions = "r--";
                      break;
                  case 5:
                      otherPermissions = "r-x";
                      break;
                  case 6:
                      otherPermissions = "rw-";
                      break;
                  case 7:
                      otherPermissions = "rwx";
                      break;
              }
              String output = firstBinary + " " + secondBinary + " " + thirdBinary + " and " + ownerPermissions + " " + groupPermissions + " " + otherPermissions;
  
              return output;
          }
  }
  </code></pre>