Switch圖形練習

來源:互聯網
上載者:User

標籤:

//package IfAndSwitchs;
import java.util.Scanner;

public class Mianji {
public static void main(String[] args){

//(1)這句話表達建立一個輸入的對象
Scanner s =new Scanner(System.in);
System.out.print("請選擇圖形 1.長方形 2.圓 3.三角形");
//(2)擷取到使用者控制台輸入的資料,存放在choose裡面
int choose = s.nextInt();

/*(3)判斷使用者輸入的是什麼資料*/
switch(choose){
case 1:
System.out.print("你選擇的是長方形");
/*(4)根據不同的選擇在不同的case下面嵌套switch*/
/*開始*/
System.out.print("請輸入長方形的長");
int width = s.nextInt();
System.out.print("請輸入長方形的寬");
int height = s.nextInt();
System.out.print("面積為:"+width*height);
/*結束*/
break;
case 2:
System.out.print("你選擇的是圓形");
/*(5)根據不同的選擇在不同的case下面嵌套switch*/
/*開始*/
System.out.print("請輸入圓的半徑");
float pI=3.14
System.out.print("面積為:"+(PI*r*r));
break;
case 3:
System.out.print("你選擇的是三角形");
System.out.print("請輸入三角形的邊長");
int bianchang = s.nextInt();
System.out.print("請輸入三角形的高");
int gao = s.nextInt();
System.out.print("面積為:+(bianchang*gao)/2);
break;

default:System.out.print("錯誤");
}

}
}

Switch圖形練習

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.