JavaWeb開發實戰指南----if嵌套

/**
*@Title: ${filename}
*@Package: ${package_name}
*@Description: ${todo}
*
if嵌套
if當中有if,即條件中還有條件

if(score>=0 && score <=100)
{//合理的成績 
	if()
	{
	}
	else if ()
	{
	}
	else
	{
	}
}
*
*@author:  源代碼資料盡在"清哥好課堂"公衆號:qghktit
*@date: ${date}${time}
*@version: 1.0
*/
import java.util.Scanner;
public class  IFNesting
{
	public static void main(String[] args) 
	{
		/*
		相親
		女:有房子嗎
		男: 有      女:不好意思,我還有事,先走了
		女:有車子嗎?
		男:有       女:沒車,郊遊不方便,還是再見吧
		女:收入
			>=20000   <20000
		*/
		Scanner sc = new Scanner(System.in);
		System.out.println("請問有房嗎?(Y/N)");
		String strHome = sc.next();
		if ("Y".equals(strHome) || "y".equals(strHome))  //有房
		{
			System.out.println("他有房子!");
			System.out.println("請問有車嗎?(Y/N)");
			sc = null;  //清空緩存中的鍵入的內容
			sc = new Scanner(System.in);
			String strCar = sc.nextLine();
			if ("Y".equals(strCar) || "y".equals(strCar)) //有車
			{
				System.out.println("他有房子,有車子\n請問你的收入是多少?");
				int salary = sc.nextInt();
				if (salary >=20000)  //>=20000
				{
					System.out.println("你是我要找的對象,我們在一起吧");
				}
				else  //<20000
				{
					System.out.println("我們先相互瞭解一下吧");
				}
			}
			else  //沒車
			{
				System.out.println("沒車,郊遊不方便,還是再見吧");
			}
		}
		else  //沒房
		{
			System.out.println("不好意思,我還有事,先走了");
		}
	}
	public static void main1(String[] args) 
	{
		/*
		6歲前,可以隨意進出女廁所,女澡堂子
		6歲後,不讓進
		問:性別   
		答:男
		問:年齡

		*/
		Scanner sc = new Scanner(System.in);
		System.out.println("請問你的性別(M/F):");
		String strSex = sc.next();
		if ("M".equals(strSex) || "m".equals(strSex))  //是男孩
		{
			System.out.println("是一個男的");
			System.out.println("請問你多大了?");
			int age = sc.nextInt();
			if (age < 6)  //小於6歲
			{
				System.out.println("小朋友,來找媽媽啊");
			}
			else
			{
				System.out.println("啊,色狼");
			}
		}
		else  //是女孩子
		{
			System.out.println("不是男的,這是你的領地");
		}	
	}
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章