日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > java >内容正文

java

exit java_没有System.exit,如何退出Java程序?(通过用户输入?)

發布時間:2023/12/19 java 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 exit java_没有System.exit,如何退出Java程序?(通过用户输入?) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

這是我的代碼。我不確定如何使用返回值退出程序。有任何想法嗎?這是我完成任務的最后一步。重要區域標有我聽到了返回的消息,但是當我將main中的void更改為int時,程序會說main必須為void。

import java.util.Scanner;

public class CommissionCalculator {

public static void main(String args[]) {

// Initialize a Scanner to read input from the command line

Scanner ItemSelect = new Scanner(System.in);

double comp = 200.00;

double item1 = 239.99;

double item2 = 129.75;

double item3 = 99.95;

double item4 = 350.89;

double comm = 0.09;

int choice;

/* Note that we'll be doing this at least once and most likely multiple times...

* Prompt the user with a menu of the four items and their values (this information is included in the problem statement)

*/

System.out.println("Item\tValue");

System.out.println("1\t$239.99");

System.out.println("2\t$129.75");

System.out.println("3\t$99.95");

System.out.println("4\t$350.89");

/* Display the user's current compensation */

System.out.printf("Current compensation: $%.2f", comp);

/*

* Prompt and take input from the user (you may assume that they will only enter int values)

* They'll enter an item number (1 - 4) to record its sale or 0 to exit

*

* NOTE: THE U0SER DOES NOT ENTER PRICES DIRECTLY... THEY ENTER ITEM NUMBERS TO INDICATE WHAT WAS SOLD

* NOTE: THE USER MAY ENTER THE SAME ITEM NUMBRER MULTIPLE TIMES

*

* If the user provides invalid input (a value other than 0 - 4) display "ERROR: Invalid input!" and prompt them again

*/

do

{

System.out.print("\nPlease select an item from the " +

"list above (or enter 0 to exit): ");

choice = ItemSelect.nextInt();

{

if (choice != 1 && choice != 2 && choice != 3 && choice != 4 && choice != 0)

{

do

{

System.out.print("ERROR: Invalid Input!\n");

System.out.println("Item\tValue");

System.out.println("1\t$239.99");

System.out.println("2\t$129.75");

System.out.println("3\t$99.95");

System.out.println("4\t$350.89");

System.out.printf("Current compensation: $%.2f", comp);

System.out.print("\nPlease select an item from the " +

"list above (or enter 0 to exit): ");

choice = ItemSelect.nextInt();

if (choice == 1)

{

comp += (comm * item1);

System.out.printf("Current compensation: $%.2f", comp);

}

if (choice == 2)

{

comp += (comm * item2);

System.out.printf("Current compensation: $%.2f", comp);

}

if (choice == 3)

{

comp += (comm * item3);

System.out.printf("Current compensation: $%.2f", comp);

}

if (choice == 4)

{

comp += (comm * item4);

System.out.printf("Current compensation: $%.2f", comp);

}

if (choice == 0)

{

System.out.printf("Total Earnings: $%.2f", comp);

System.exit(0); ///

}

}while (choice != 1 && choice != 2 && choice != 3 && choice != 4 && choice != 0);

}

else

{

if (choice == 1)

{

comp += (comm * item1);

System.out.printf("Current compensation: $%.2f", comp);

}

if (choice == 2)

{

comp += (comm * item2);

System.out.printf("Current compensation: $%.2f", comp);

}

if (choice == 3)

{

comp += (comm * item3);

System.out.printf("Current compensation: $%.2f", comp);

}

if (choice == 4)

{

comp += (comm * item4);

System.out.printf("Current compensation: $%.2f", comp);

}

if (choice == 0)

{

System.out.printf("Total Earnings: $%.2f", comp);

System.exit(0);

}

}

}

}while (choice != 0);

/* After the user enters 0, display the salesperson's earnings in the format "Total earnings: $NNN.NN" and exit

* For example, if the salesperson sold two item 3s this week the final output would be "Total earnings: $217.99"

*/

if (choice == 0)

{

System.out.printf("Total Earnings: $%.2f", comp);

System.exit(0); ///

}

ItemSelect.close();

System.exit(0); ///

}

}

總結

以上是生活随笔為你收集整理的exit java_没有System.exit,如何退出Java程序?(通过用户输入?)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。