1. 程式人生 > >switch....case寫的介面如何返回上一級

switch....case寫的介面如何返回上一級

1.在每一個switch......case外套一個while迴圈

import java.util.Scanner;


 class Menu1 {
	void showLoginMenu(){
		System.out.println("\t\t歡迎使用我行我素管理系統");
		System.out.println("\n\t\t1.登入系統");
		System.out.println("\n\t\t2.退出");
		System.out.println("\n**********************************");
	}
	void  showMainMenu(){
		System.out.println("\t\t我行我素購物管理主選單");
		System.out.println("\n**************************************");
		System.out.println("\n\t\t1.客戶資訊管理");
		System.out.println("\n\t\t2.真情回顧");
		System.out.println("\n**************************************");
	}
	void showCustMenu(){
		System.out.println("\t\t客戶資訊管理選單");
		System.out.println("\n**************************************");
		System.out.println("\n\t\t1.客戶資訊");
		System.out.println("\n\t\t2.購物金額");
		System.out.println("\n**************************************");
	}
	void showSendMenu(){
		System.out.println("\n\t\t真情回饋選單");
		System.out.println("\n**************************************");
		System.out.println("\n\t\t1.幸運大放送");
		System.out.println("\n\t\t2.幸運抽獎");
		System.out.println("\n\t\t3.生日問候");
		System.out.println("\n**************************************");
	}
}
 
 public class Menu {

		public static void main(String[] args) {
			int n=0,b=0,c=0,d=0;			
				Menu1 m=new Menu1();
				m.showLoginMenu();
				Scanner input=new Scanner(System.in);
				System.out.print("請選擇,輸入數字:");
				n=input.nextInt();
				do{
				switch(n){
				   case 1:do {
					   m.showMainMenu();
					   System.out.print("請選擇,輸入數字或按0返回上一級:");
					   b=input.nextInt();
					   switch(b){
			               case 1:do {
			            	   m.showCustMenu();
			            	   System.out.print("請選擇,輸入數字或按0返回上一級:");
			            	   c=input.nextInt();
			            	   switch(c){
			                      case 1:System.out.println("客戶資訊");break;
			                      case 2:System.out.println("購物金額");break;			                      
			                      }
			            }while(c!=0);
		                   break;
			               case 2:do {
			            	   m.showSendMenu();
			                   System.out.print("請選擇,輸入數字或0返回上一級:");
			                   d=input.nextInt();
			                   switch(d){
			                      case 1:System.out.println("執行幸運大放送");break;
			                      case 2:System.out.println("執行幸運抽獎");break;
			                      case 3:System.out.println("執行生日問候");break;
			                      }
			               }while(d!=0)	;
			               break;
			          }				   					   
				   }while(b!=0);	
				   break;
				   case 2:System.out.println("退出");
				}	
			}while(n!=2);
		}
 }
 

 

2.套一個while迴圈
package day05Z;

import java.util.Scanner;

 class StartSMS1 {
	void show(){
		System.out.println("\t\t歡迎使用我行我素管理系統");
		System.out.println("\n\t\t1.登入系統");
		System.out.println("\n\t\t2.退出");
		System.out.println("\n**********************************");
	}
}
public class StartSMS {
	public static void main(String[] args) {
		StartSMS1 s=new StartSMS1();
		String s1,s2;
		boolean bool=true;
		while(bool){
			s.show();
			Scanner input=new Scanner(System.in);
			System.out.print("請選擇,輸入數字:");
			int a=input.nextInt();
		    switch(a){
		    case 1:System.out.print("請輸入使用者名稱:");
		          s1=input.next();
		    		System.out.print("請輸入密碼:");
		    		s2=input.next(); 
		    		if(s1.equalsIgnoreCase("admin")&&s2.equalsIgnoreCase("0000")){
		    			System.out.println("@@登陸成功:
[email protected]
@"); bool=false; }else{ System.out.println("@@您沒有許可權進入系統,請重新登陸。@@"); } break; case 2:System.out.println("退出"); break; } System.out.println(); } } }

相關推薦

switch....case介面如何返回一級

1.在每一個switch......case外套一個while迴圈 import java.util.Scanner; class Menu1 { void showLoginMenu(){ System.out.println("\t\t歡迎使用我行我

在 UIView 新增返回一級操作介面(手勢)

系統:手勢 ——> target ----> action 自己建立的介面新增手勢 :UIView —> 建立手勢 —> target —> action 第一種方法 獲取到系統的返回上一級介面的手勢,新增到 UIView 上

IOS--如何從第N級介面返回一級介面(即新增在UITabbarController的UIController)

//第N個介面的返回按鈕點選事件 - (void)orderForBackBarButtonItemAction { AppDelegate *app = (AppDelegate *)[U

iOS側滑返回一級介面

- (id)initWithRootViewController:(UIViewController *)rootViewController {     self = [super initWithRootViewController:rootViewController

JavaScript特效之前進,後退(返回一級

函數調用 dsm war button 之前 type 後退 white 一個 在頁面上增加前進,後退(返回上一級)功能: 方式一:使用函數 <script> function goback(){ history.go(-1);//返回或者histor

在CentOS 7 設置返回一級目錄的快捷鍵為 Backspace

logs fff ext color con 重啟 line n-n 文件 參考這裏。 編輯文件: $ vi ~/.config/nautilus/accels 找到這一行: ; (gtk_accel_path "<Actions>/ShellAction

Android 使用SwipeBackLayout實現滑動返回一級頁面——實戰來襲

color tran 創建 line 不讓 -s sdn edi 會有 我們知道。APP在設計上習慣性的把返回button放在屏幕的左上角,那麽,在非常多時候(尤其是大屏幕手機),操作改返回button,就會有諸多不便了。為了更加方便實現“返回”功能。如今的一些

iOS 開發 右滑返回一級控制器

nvi add str class change bool poi exc iges #import <objc/runtime.h> @interface UINavigationController (Transition)<UIGestureReco

vue路由跳轉 返回一級 this.$router.go(-1) 和返回到指定頁面this.$router.push('/home')

name nbsp style span button pre 頁面 -c out 1,點擊返回上一頁<button @click="goback">goback</button> methods:{ goback(){} this.$route

react 點選按鈕返回一級路由

在這我是以一個點選圖示返回為例的 1. 在要點選的按鈕或者圖片上新增事件 <img src="images/back.png" alt="" onTouchStart={this.backClick}/>   2. 事件編寫  // 點選

Vue怎麼返回一級返回一頁面

程式碼如下: <button @click='prev'>返回上一級</button> <script> methods:{ prev()

xpath選擇兄弟節點、返回一級和選擇多個屬性

選擇兄弟節點 選擇前N位的div標籤 preceding-sibling::div[N] 選擇後N位的div標籤 following-sibling::div[N] 選擇上一級 ../ 結合使用 //td[text()='xxx']/../fo

C# /.net 返回一級目錄

  //獲取當前目錄下         //string path2 = System.Environment.CurrentDirectory + @"\\Web.config";         /// &

微信小程式(三):返回一級頁面並重新整理(頁面棧)

在很多業務場景之下,需要返回上一級頁面,並進行重新整理,在微信小程式中的wx.navigateBack方法中,返回上一頁是不會重新整理的。如果上一頁的頁面載入是在onLoad方法中觸發的話,那麼可以修改為在onShow方法中觸發。 onLoad(Object query):

js/jquery 返回一級頁面並重新整理

剛開始從網上找來的都是history.go(-1),然後自己用的時候,發現並沒有重新整理。 因為正在做東西,第一個頁面是展示資訊,然後可以從按鈕跳轉到更新頁面,當更新成功後返回上一級,第一個頁面應該會把更新的內容展示出來,但是在使用history.go(-1)

WebView返回一級頁面

@Override public void onBackPressed() { if (webView.canGoBack()){ if(webView.get

返回一級頁面

需求重現 頁面跳轉時,點選返回有時會陷入迴圈,無法逐級向上返回 解決辦法 js檔案 var historyUtils = { add : function (url) { var historyArray = hist

iOS 9 適用,使用Button實現簡單的檢視跳轉與返回一級。(初級)

搭建平臺;Xcode 7.1— iOS 9 一、新建兩個檢視,並通過 Button實現跳轉 並在第一個檢視上放一個Button控制元件。滑鼠點選Button控制元件,按住Ctrntrol鍵不放,出現藍色小圓點。直接把藍色小圓點拖動到第二個檢視,其間有

讓WebView可以返回一級

@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCOD

關於JS中返回一級

返回上一級,有兩種情況,第一:重新整理上一個頁面;第二:不重新整理上一個頁面。首先是,重新整理上一個頁面,不保留上一個頁面的任何操作;(1)<a href="JavaScript:history.go(-1)">返回上一級</a>;(2)使用requi