zoukankan      html  css  js  c++  java
  • 0706作业

    1:for循环的格式?要能看懂执行流程。
      for(初始化表达式;循环条件表达式;循环后操作表达式){
        循环体
      }
    用for循环完成如下案例

    求和

    public class Sum0706 {
    	public static void main(String[] args) {
    		int sum = 0;
    
    		for (int i = 1;i <= 20 ;i++ ) {
    			sum += i;
    		}
    
    		System.out.println(sum);
    	}
    }
    

      

    求偶数和

    class Sum0706_Even {
    	public static void main(String[] args) {
    		int sum = 0; //定义变量 和
    
    		for (int i = 1;i <= 20 ;i++ ) {
    			if (i % 2 == 0) { // 判断是不是偶数
    				sum += i;
    			}
    		}
    
    		System.out.println(sum);
    	}
    }
    

      

    求奇数和

    class Sum0706_Uneven {
    	public static void main(String[] args) {
    		int sum = 0;
    
    		for (int i = 1;i <= 20 ;i++ ) {
    			if (i % 2 != 0) {
    				sum += i;
    			}
    		}
    
    		System.out.println(sum);
    	}
    }
    

      

    打印水仙花数
    统计水仙花数

    class ShuiXianHuaShu {
    	public static void main(String[] args) {
    		//定义计数器
    		int count = 0;
    
    		//定义水仙花数
    		for (int i=100;i<=999 ;i++ ) {
    			int ge = i / 1 %10;
    			int shi = i / 10 % 10;
    			int bai = i / 100 % 10;
    			if (ge * ge * ge + shi * shi * shi + bai * bai * bai == i) {
    				count += 1;
    				System.out.println(i+"是水仙花数");
    			}
    		}
    
    		System.out.println("水仙花数的个数是:"+count);
    	}
    }
    

      

    九九乘法表

    class Cheng99 {
    	public static void main(String[] args) {
    		for (int i = 1;i<=9 ;i++ ) {
    			for (int j = 1;j <= i ; j++) {
    				System.out.print(j + "*" + i + "=" + j*i + "	");
    			}
    
    			System.out.println();
    		}	
    	}
    }
    

      

    2:while循环的格式?要能看懂执行流程
      初始化表达式;
      while(条件表达式){
      循环体;
      循环后操作表达式;
      }
    3:break,continue和return分别有什么用?
      break: 用在(switch case 语句 | for 循环语句) 中 ,用于跳出本语句;
      continue: 用在for循环语句中,结束本次循环,执行下次循环;
      return: 结束方法
    4:函数(方法)的概念?函数的格式?格式的解释说明
      修饰语句(public static) + 返回语句(void) +方法名 (main方法) + 参数(参数类型及个数)
    5:函数的调用
    A:明确返回值类型的函数调用
    B:void类型的函数调用

    6:函数的练习:
    A:求两个数据之和
    B:判断两个数据是否相等
    C:获取两个数中较大的值

    import java.util.Scanner;
    
    class Test_0706 {
        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            System.out.println("请输入数a:");
            int a = sc.nextInt();
            System.out.println("请输入数b:");
            int b = sc.nextInt();
    
            int sum = a + b;
            System.out.println("你输入的两个数的和是" + sum);
    
            if (a == b) {
                System.out.println("你输入的两个数相等");
            }else {
                System.out.println("你输入的两个数不相等");
            }
    
            int c = (a >= b)? a : b;
            System.out.println("你输入的两个数中较大的数是" + c);
        }
    }

    D:打印m行n列的星形矩形

    import java.util.Scanner;
    
    class PrintRectangle {
        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            System.out.println("请输入行数m:");//友好提示
            int m = sc.nextInt();
            System.out.println("请输入列数n:");//友好提示
            int n = sc.nextInt();
    
            for (int i = 1;i <=m ;i++ ) {
                for (int j = 1 ;j <= n ;j++ ) {
                    System.out.print("* ");
                }
                System.out.println();
            }
            System.out.println();
    
            System.out.println("这就是你所要的星型矩形");
        }
    }

    E:打印nn乘法表

    class ChengFaBiao_nn {
        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            System.out.println("请输入行数n:");//友好提示
            int n = sc.nextInt();
            chengFaBiao(n);
        }
        
        public static void  chengFaBiao(int n){
            for (int i = 1;i <=n ;i++ ) {
                for (int j = 1 ;j <= i ;j++ ) {
                    System.out.print(j + "*" + i + "=" + j*i + "	");
                }
                System.out.println();
            }
            System.out.println();
    
            System.out.println("这就是你所要的"+n+n+"乘法表");
        }
    }

    7:什么是函数重载?以及函数重载的练习?把讲过的案例练习一次即可

      在同一个类中,方法名一样,参数类型和参数个数不同的两个方法

  • 相关阅读:
    jMeter 里 CSV Data Set Config Sharing Mode 的含义详解
    如何使用 jMeter Parallel Controller
    使用 Chrome 开发者工具 coverage 功能分析 web 应用的渲染阻止资源的执行分布情况
    使用 Chrome 开发者工具的 lighthouse 功能分析 web 应用的性能问题
    关于 SAP 电商云首页加载时触发的 OCC API 请求
    SAP UI5 确保控件 id 全局唯一的实现方法
    SAP 电商云 Accelerator 和 Spartacus UI 的工作机制差异
    介绍一个好用的能让网页变成黑色背景的护眼 Chrome 扩展应用
    Chrome 开发者工具 performance 标签页的用法
    Client Side Cache 和 Server Side Cache 的区别
  • 原文地址:https://www.cnblogs.com/zhangzheng1989/p/9275460.html
Copyright © 2011-2022 走看看