任务卡
任务名称: 自动关机程序
1、提示用户,欢迎使用某某 关机程序
2、提示用户,输入倒计时关机的秒数
3、根据用户输入的秒数,进行自动关机
4、开始自动关机时,提示用户xxx秒后关机
自动关机和取消自动关机代码:
package xyz.chaitc.demo;
import java.io.IOException;
public class Demo1 {
//代码分为结构定义语句, 和 功能执行语句
//功能执行语音必须以分号结尾
public static void main(String[] args) throws IOException {
// (单行注释//)注释:对代码的解释和说明,提高代码的可读性,不会被计算机作为指令来执行
// 从 //开始 到 该行结束
//关机
// Runtime.getRuntime().exec("shutdown -s -t 1000");
//取消关机
Runtime.getRuntime().exec("shutdown -a");
}
}
自动关机程序代码:
package xyz.chaitc.demo;
import java.io.IOException;
import java.util.Scanner;
public class Demo3 {
public static void main(String[] arg) throws IOException {
//1、欢迎使用ctc关机程序
System.out.println("**********************************");
System.out.println("welcome to ctc's shutdown appstory");
System.out.println("**********************************");
//2、提示用户,输入计时关机的秒数
@SuppressWarnings("resource")
Scanner user_inputScanner = new Scanner(System.in);
System.out.println("Please input shutdown times/(s):");
//3、根据用户输入的秒数,进行自动关机
String textString = user_inputScanner.nextLine();
//int text = Integer.valueOf(textString);
//String cmdString = "shutdown -s -t "+text;
//String cmdString = "shutdown -s -t 300";
String cmdString = "shutdown -s -t "+textString;
Runtime.getRuntime().exec(cmdString);
//4、开始自动关机时,提示用户XXX秒后关机
System.out.println("your system will in "+textString+"s shutdown...");
}
}
Eclipse导出jar包流程:
执行jar包命令:
java -jar ***.jar