當前位置:編程學習大全網 - 網站源碼 - (OOP)求壹個結賬的Java代碼啊,要求客戶可以從菜單裏面選擇物品,最後結賬在控制臺。

(OOP)求壹個結賬的Java代碼啊,要求客戶可以從菜單裏面選擇物品,最後結賬在控制臺。

public class Test {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

String str = "";

while(true) {

System.out.println("請輸入壹個字符:");

str = sc.nextLine();

if(str=="exit") // 如果字符串為"exit",退出循環

break;

if(str.length()==1) {

char c = str.charAt(0);

System.out.println("它對應的ASCII碼為:" + (int)c); //(int)c將c強制轉換為它的ascii碼

}

else

System.out.println("請輸入壹位字符。");

}

sc.close();

}

}

  • 上一篇:Java 運行時JNI問題?
  • 下一篇:添加信息框源代碼
  • copyright 2024編程學習大全網