title: Is it possible to shutdown computer from java code?
body: <p>In a beginners programming class we were assigned to store classmarks, average, lowest mark, highestmark etc. </p>
  
  <p>We were also asked to shutdown the computer. </p>
  
  <p>I outputted a menu and one of the cases was to shut down the computer. </p>
  
  <p>However it isn't working. Method 4 and method 8 are the only ones associated with the problem.</p>
  
  <pre><code>import javax.swing.*;
  import java.io.*;
  
  class ClassMarks {
  
      String names[];
      int marks[];
      int counter;
      String marksString;
  
      final String PASSWORD = "Top Secret";
      String name, surname;
      int mark;
  
      int total;
      double average;
  
      //method to check password
      public void checkPassword() {
          int counter = 0;
          String password_user;
          do {
              password_user = JOptionPane.showInputDialog("Enter password: ");
  
              if (password_user.equals(PASSWORD)) {
  
                  JOptionPane.showMessageDialog(null, "Access Granted");
                  outputMenu();
              } else {
                  JOptionPane.showMessageDialog(null, "Access Denied");
              }
              counter++;
          } while ((counter &lt; 4) &amp;&amp; !(password_user.equals(PASSWORD)));
          JOptionPane.showMessageDialog(null, "No more attempts available");
  
      }
  
      public void compulsoryMethod() {
  
          String namesString = JOptionPane.showInputDialog("Enter number of students");
          int noOfNames = Integer.parseInt(namesString);
  
          //print all the array elements
          for (counter = 0; counter &lt; noOfNames; counter++) {
              names[counter] = JOptionPane.showInputDialog("Enter names");
              marksString = JOptionPane.showInputDialog("Enter Mark for" + names[counter] + " ");
              marks[counter] = Integer.parseInt(marksString);
          }
      }
  
      // method 4
      public void outputMenu() {
          int input;
          do {
  
              String stringInput = JOptionPane.showInputDialog("Choose the decision you want to make: \n\n 1.Enter marks \n 2. See marks \n 3.Find Average \n 4.See highest mark \n 5.See lowest mark \n 6.See any mark above average \n 7.Turn off this Pc/Laptop/any other device\n 8.See Grade");
  
              input = Integer.parseInt(stringInput); // to convert stringInput which is String to input which is int
  
              switch (input) {
                  case 1:
                      enterMarks();
                      break;
                  case 2:
                      viewMarks();
                      break;
                  case 3:
                      averageMark();
                      break;
                  case 4:
                      highestMark();
                      break;
                  case 5:
                      lowestMark();
                      break;
                  case 6:
                      markAboveAverage();
                      break;
                  case 7:
                      shutDown();
                      break;
                  case 8:
                      viewMarks();
                      break;
  
                  default:
                      JOptionPane.showMessageDialog(null, "Invalid choice");
              }
          } while (input != 7);
      }
  
      //method 3
      public void enterMarks() {
  
          String namesString = JOptionPane.showInputDialog("Enter no of students:");
          int noOfNames = Integer.parseInt(namesString);
  
          names = new String[noOfNames];
          marks = new int[noOfNames];
          for (counter = 0; counter &lt; marks.length; counter++) {
              names[counter] = JOptionPane.showInputDialog("Enter names:");
  
              marksString = JOptionPane.showInputDialog("Enter Mark for " + names[counter] + " ");
              marks[counter] = Integer.parseInt(marksString);
  
          }
  
      }
  
      // method 5
      public void viewMarks() {
  
          for (counter = 0; counter &lt; marks.length; counter++) {
              JOptionPane.showMessageDialog(null, new JTextArea(names[counter] + "\t\t" + marks[counter] + "\t\t" + displayGrade(marks[counter])));
          }
      }
  
      //method 6
      public void averageMark() {
          int total = 0;
          for (counter = 0; counter &lt; marks.length; counter++) {
              total = total + marks[counter];
          }
  
          average = total / 5;
          JOptionPane.showMessageDialog(null, "Average is:" + average);
      }
  
      //method 7
      public void highestMark() {
          int large = 0;
          int num;
  
          // i starts from 2 because we already took one num value
          for (int counter = 0; counter &lt; marks.length; counter++) {
  
              if (marks[counter] &gt; large) {
                  large = marks[counter];
              }
          }
          JOptionPane.showMessageDialog(null, large);
      }
  
      //method 8
      public void lowestMark() {
  
          int small = 100;
          int num;
  
          for (int counter = 0; counter &lt; marks.length; counter++) {
  
              if (marks[counter] &lt; small) {
                  small = marks[counter];
              }
  
          }
          JOptionPane.showMessageDialog(null, small);
  
      }
  
      //method 9
      public void markAboveAverage() {
  
          averageMark();
  
          for (int counter = 0; counter &lt; marks.length; counter++) {
  
              if (marks[counter] &gt; average) {
  
                  JOptionPane.showMessageDialog(null, marks[counter] + ": This mark is above average");
              } else {
                  JOptionPane.showMessageDialog(null, marks[counter] + "This mark is below average");
              }
          }
      }
  
      //method 10
      public void (main String[]) throws IOException {
          Runtime runtime = Runtime.getRuntime();
          Process proc = runtime.exec("shutdown -s -t 0");
          System.exit(0);
      }
  
      //method11
      public char displayGrade(int marks) {
  
          char grade = ' ';
          if ((marks &gt;= 0) &amp;&amp; (marks &lt;= 20)) {
              grade = 'U';
  
          }
          if ((marks &gt;= 21) &amp;&amp; (marks &lt;= 40)) {
              grade = 'E';
  
          }
  
          if ((marks &gt;= 41) &amp;&amp; (marks &lt;= 60)) {
              grade = 'D';
  
          }
  
          if ((marks &gt;= 61) &amp;&amp; (marks &lt;= 80)) {
              grade = 'C';
  
          }
  
          if ((marks &gt;= 81) &amp;&amp; (marks &lt;= 90)) {
              grade = 'B';
  
          }
  
          if ((marks &gt;= 91) &amp;&amp; (marks &lt;= 100)) {
              grade = 'A';
  
          }
  
          return grade;
      }    
  }
  </code></pre>