1.for(初始化表达式;条件表达式;循环后的操作表达式){

循环体;

}

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

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

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

class Test_ShuiXian {
public static void main(String[] args) {
for (int i = 100;i <= 999 ;i++ ) {
int ge = i % 10;
int shi = i / 10 % 10;
int bai = i / 100 % 10;
if (ge * ge * ge + shi * shi * shi +bai * bai * bai == i) {
System.out.println(i);
}
}
}
}

class Test_ShuiXian {
public static void main(String[] args) {
int count = 0;
for (int i = 100;i <= 999 ;i++ ) {
int ge = i % 10;
int shi = i / 10 % 10;
int bai = i / 100 % 10;
if (ge * ge * ge + shi * shi * shi +bai * bai * bai == i) {
count++;
}
}
System.out.println(count);
}
}

class Test_99 {
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 + "=" +i*j + "\t");
}
System.out.println();
}
}
}

2.初始化语句;

while(判断条件语句){

循环体语句;

控制条件语句;

}

3.break:跳出循环

continue:终止本次循环,继续下次循环

return:终止方法

4.方法是类中的一段独立的代码区域具有独立的功能

格式:

修饰符 返回值类型 方法名称(数据类型 名称1,数据类型 名称 2){

code...;

return 返回值;

}

分析main方法

修饰符 public static

返回值类型 数据类型返回值类型是什么就写什么,如果没有就写void

方法名称——自定义的名称写法和变量名一致

(数据类型 名称1,数据类型 名称2,...)——参数列表(形参列表)

(String[] args)——形参列表

5.A.修饰符 返回值类型 方法名称(数据类型 名称1,数据类型 名称2){

code...;

return 返回值;

}

B.

public static void main(String[] args){

}

6.A.

import java.util.Scanner;
class FunctionSum {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入第一个数");
int a = sc.nextInt();
System.out.println("请输入第二个数");
int b = sc.nextInt();
sum(a,b);
}
public static void sum(int a, int b){
System.out.println(a+b);
}
}

B.

import java.util.Scanner;
class FunctionCompare {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入第一个数:");
int a = sc.nextInt();
System.out.println("请输入第二个数:");
int b = sc.nextInt();
compare(a,b);
}
public static void compare(int a, int b){
if (a == b) {
System.out.println("相等");
}else{
System.out.println("不相等");
}
}
}

C.

import java.util.Scanner;
class FunctionMax {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入第一个数:");
int a = sc.nextInt();
System.out.println("请输入第二个数:");
int b = sc.nextInt();
max(a,b);
}
public static void max(int a, int b){
if (a > b) {
System.out.println(a);
}else{
System.out.println(b);
}
}
}

D.

import java.util.Scanner;
class FunctionRectangle {
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();
rectangle(m,n);
}
public static void rectangle(int m, int n){
for (int i = 1;i <= m ;i++ ) {
for (int j = 1;j <= n ;j++ ) {
System.out.print("* ");
}
System.out.println();
}
}
}

E.

import java.util.Scanner;
class FunctionMultiplication {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入n:");
int n = sc.nextInt();
multiplication(n);
}
public static void multiplication(int n){
for (int i = 1;i <= n ;i++ ) {
for (int j = 1;j <= i ;j++ ) {
System.out.print(j + "*" + i + "=" +i*j + "\t");
}
System.out.println();
}
}
}

7.在同一个类中出现了多个同名的方法,但是参数列表不同。

day04作业的更多相关文章

  1. python day04 作业答案

    1. 1) li=['alex','WuSir','ritian','barry','wenzhou'] print(len(li)) 2) li=['alex','WuSir','ritian',' ...

  2. python day04作业

  3. day04 作业

    一.简述Python的五大数据类型的作用.定义方式.使用方法: 数字类型 整型 作用:描述年龄 定义方式: x = 10 y = int('10') 使用方法: + - * / % // ** 如果需 ...

  4. python 作业

    Linux day01 计算机硬件知识整理 作业要求:整理博客,内容如下 编程语言的作用及与操作系统和硬件的关系 应用程序->操作系统->硬件 cpu->内存->磁盘 cpu与 ...

  5. DSB

    Linux day01 计算机硬件知识整理 作业要求:整理博客,内容如下 编程语言的作用及与操作系统和硬件的关系 应用程序->操作系统->硬件 cpu->内存->磁盘 cpu与 ...

  6. Python作业篇 day04

    ###一.写代码,有如下列表,按照要求实现每一个功能 li=['alex','bibi','cc0','didi'] #1.计算列表的长度 #2.列表中追加元素'seven',并输出添加后的列表 #3 ...

  7. python开发学习-day04(迭代器、生成器、装饰器、二分查找、正则)

    s12-20160123-day04 *:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: ...

  8. python10作业思路及源码:类Fabric主机管理程序开发(仅供参考)

    类Fabric主机管理程序开发 一,作业要求 1, 运行程序列出主机组或者主机列表(已完成) 2,选择指定主机或主机组(已完成) 3,选择主机或主机组传送文件(上传/下载)(已完成) 4,充分使用多线 ...

  9. SQLServer2005创建定时作业任务

    SQLServer定时作业任务:即数据库自动按照定时执行的作业任务,具有周期性不需要人工干预的特点 创建步骤:(使用最高权限的账户登录--sa) 一.启动SQL Server代理(SQL Server ...

随机推荐

  1. Java之初学异常

    异常 学习异常的笔记记录 异常 异常的概念 指的是程序在执行过程中,出现的非正常的情况,最终会导致JVM的非正常停止. 异常指的并不是语法错误,语法错了,编译不通过,不会产生字节码文件,根本不能运行. ...

  2. bzoj3672: [Noi2014]购票(树形DP+斜率优化+可持久化凸包)

    这题的加强版,多了一个$l_i$的限制,少了一个$p_i$的单调性,难了好多... 首先有方程$f(i)=min\{f(j)+(dep_i-dep_j)*p_i+q_i\}$ $\frac {f(j) ...

  3. bzoj3473: 字符串 && bzoj3277串

    3473: 字符串 Time Limit: 20 Sec  Memory Limit: 256 MBSubmit: 121  Solved: 53[Submit][Status][Discuss] D ...

  4. 21天实战caffe笔记_第一天

    1 深度学习术语 深度学习常用名词:有监督学习.无监督学习.训练数据集.测试数据集.过拟合.泛化.惩罚值(损失loss); 机器自动学习所需三份数据:训练集(机器学习的样例),验证集(机器学习阶段,用 ...

  5. k-Nearest Neighbor algorithm 思想

    转载      KNN--K最邻近算法思想 KNN算法的决策过程 k-Nearest Neighbor algorithm  上图中,绿色圆要被决定赋予哪个类,是红色三角形还是蓝色四方形?如果K=3, ...

  6. 4.tar的各个参数详解

    转于:https://blog.csdn.net/liuyundemhsg/article/details/52525028 参数:-c :建立一个压缩文件的参数指令(create 的意思):-x : ...

  7. 01 C++ 多线程入门实例

    1.可复用的完整实例 #include <iostream> #include <thread> #include <mutex> using namespace ...

  8. Ansible9:条件语句

    目录 一.when 1.基本用法 2.在when中使用jinja2的语法 3.使用bool值作为when的判断条件 4.在when中使用defined关键字 5.when在循环语句中的使用方法 6.在 ...

  9. 又一家药企IPO被拒,原因竟然是……

    版权所有,未经授权不得转载,QQ:231469242 导读 近日,中国证监会官网发布公告,河南润弘制药首发未IPO能通过,成为今年第4家IPO被否的制药企业.中国证监会拒绝润弘制药的原因是润弘制药产品 ...

  10. Logistic Ordinal Regression

    sklearn实战-乳腺癌细胞数据挖掘(博客主亲自录制视频教程) https://study.163.com/course/introduction.htm?courseId=1005269003&a ...