codescracker


java

Java Program to Shutdown Computer



« Previous Program Java Tutorial »


Shutdown Computer

To shutdown computer in Java programming, you have to use the command shutdown -s -t. You can also specify the time after which you want to make your computer turn off or shutdown.

Java Programming Code to Shutdown Computer

Following Java program ask to the user to enter the number of seconds to make your computer shutdown after the specified number of seconds :

/* Java Program Example - Shutdown Computer */
		
import java.io.*;

public class JavaProgram
{
    public static void main(String args[]) throws IOException
    {
        Runtime runtime = Runtime.getRuntime();
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		
        System.out.print("Enter No. of Seconds after which You want your Computer to Shutdown :");
        long a=Long.parseLong(br.readLine());
		
        Process proc = runtime.exec("shutdown -s -t " +a);
		
        System.exit(0);
    }
}

Same Program in Other Languages

You may also like to learn and practice the same program in other popular programming languages:


« Previous Program Java Tutorial »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test