乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      for的應(yīng)用

       印度阿三17 2021-01-24

      增強for循環(huán)

      ?int []s={10,20,30,40,50};
      ? ? ? ? //常規(guī)
      ? ? ? ? ?for (int i = 0; i < 5; i ) {
      ? ? ? ? ? ? ?System.out.println(s[i]);
      ? ? ? ? }
      ? ? ? ? ?System.out.println("=========================================");
      ? ? ? ? ?//增強for
      ? ? ? ? ?for(int j:s) {
      ? ? ? ? ? ? ?System.out.println(j);
      ? ? ? ? }

      image-20210120123851469

      增強就是簡化語句

      練習

      打印三角形

      ?for (int i = 0; i <= 5; i  ) {
      ? ? ? ? ? ? ?for (int i1 = 5; i1 >=i; i1--) {
      ? ? ? ? ? ? ? ? ?System.out.print(" ");
      ? ? ? ? ? ? }
      ? ? ? ? ? ? ?for (int i2 = 1; i2 <= i; i2 ) {
      ? ? ? ? ? ? ? ? ?System.out.print("*");
      ? ? ? ? ? ? }
      ? ? ? ? ? ? ?for (int i3 = 1; i3 < i; i3 ) {
      ? ? ? ? ? ? ? ? ?System.out.print("*");
      ? ? ? ? ? ? }
      ? ? ? ? ? ? ?System.out.println();
      ? ? ? ? }

      image-20210120132239800

      方法

      ?public static void main(String[] args) {
      ? ? ? ? ?int sum=add(1,2); ? //1 2 為實參
      ? ? ? ? ?System.out.println(sum);
      ? ? ? ? }
      ? public static int add (int a,int b){ //a、b為形參(形式參數(shù))
      ? ? ? ? ?return a b; ? //有返回的方法必須有return、且是方法結(jié)束的標志
      ? ? ? ? }
      ?public static double add (double a,double b){
      ? ? ? ? ?return a b;
      ? ? ? ? } //方法重載
      ?//==============================================
      ?public static void main(String[] args) {
      ? ? ? ? ?add(1,2,5,99,44);
      ??
      ? ? ? ? }
      ? ? ? ? ?public static void add (int... b)//可變參數(shù)
      ? ? ? ? {
      ? ? ? ? ?for(int i=0;i<b.length;i ){
      ? ? ? ? ? ? ?System.out.println(b[i]);
      ? ? ? ? }
      ? ? ? ? }

      方法的重載要求

      1. 方法名稱必須相同

      2. 參數(shù)列表必須不同

      3. 返回類型可以相同也可以不同

      4. 僅僅是類型不同不足以構(gòu)成重載

      可變參數(shù)

      1. 一個方法中只能指定一個可變參數(shù)

      2. 他必須是方法的最后一個參數(shù),前面可以有普通參數(shù)

      計算器

      ?public static void main(String[] args) {
      ? ? ? ? ?pro();
      ? ? }
      ? ? ?public static void pro(){
      ? ? ? ? ?System.out.println("請輸入二元計算式:");
      ? ? ? ? ?Scanner s=new Scanner(System.in);
      ? ? ? ? ?double f = s.nextDouble();
      ? ? ? ? ?String str = s.next();
      ? ? ? ? ?double g = s.nextDouble();
      ? ? ? ? ?switch (str) {
      ? ? ? ? ? ? ?case "*":
      ? ? ? ? ? ? ? ? ?System.out.println(che(f, g));
      ? ? ? ? ? ? ? ? ?pro();
      ? ? ? ? ? ? ? ? ?break;
      ? ? ? ? ? ? ?case "/":
      ? ? ? ? ? ? ? ? ?System.out.println(chu(f, g));
      ? ? ? ? ? ? ? ? ?pro();
      ? ? ? ? ? ? ? ? ?break;
      ? ? ? ? ? ? ?case " ":
      ? ? ? ? ? ? ? ? ?System.out.println(add(f, g));
      ? ? ? ? ? ? ? ? ?pro();
      ? ? ? ? ? ? ? ? ?break;
      ? ? ? ? ? ? ?case "-":
      ? ? ? ? ? ? ? ? ?System.out.println(min(f, g));
      ? ? ? ? ? ? ? ? ?pro();
      ? ? ? ? ? ? ? ? ?break;
      ? ? ? ? ? ? ?default:
      ? ? ? ? ? ? ? ? ?System.out.println("輸入有誤,請重新輸入");
      ? ? ? ? ? ? ? ? ?pro();
      ? ? ? ? ? ? ? ? ?break;
      ? ? ? ? }
      ? ? ? ? ?s.close();
      ? ? ? ? }
      ? ? ?public static double add(double a,double b){
      ? ? ? ? ?return a b;
      ? ? }
      ? ? ?public static double min(double a,double b){
      ? ? ? ? ?return a-b;
      ? ? }
      ? ? ?public static double che(double a,double b){
      ? ? ? ? ?return a*b;
      ? ? }
      ? ? ?public static double chu(double a,double b){
      ? ? ? ? ?return a/b;
      ? ? }

      ?

      來源:https://www./content-4-832651.html

        本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
        轉(zhuǎn)藏 分享 獻花(0

        0條評論

        發(fā)表

        請遵守用戶 評論公約

        類似文章 更多