java学习—day_6
来源:互联网 发布:jisucopy是什么软件 编辑:程序博客网 时间:2024/06/11 02:10
二维数组:
1.遍历,
/*
需求:二维数组的遍历
*/
class ArrayDemo
{
public static void main(String[] args)
{
int[][] array = {{23,43,43,42},{34,4,5,6},{2,4,5},
1.遍历,
/*
需求:二维数组的遍历
*/
class ArrayDemo
{
public static void main(String[] args)
{
int[][] array = {{23,43,43,42},{34,4,5,6},{2,4,5},
{3,4,7}};
for(int i = 0;i<=3;i++)
{
for(int j = 0;j<array[i].length;j++)
{
System.out.print(array[i][j]+"\t");
}
System.out.println();
}
}
}
2.
/*
公司年销售额求和
某公司的月份统计
*/
class SumArray
{
public static void main(String[] args)
{
int[][] number ={{22,45,56},{43,56,34},{24,45,65},
for(int i = 0;i<=3;i++)
{
for(int j = 0;j<array[i].length;j++)
{
System.out.print(array[i][j]+"\t");
}
System.out.println();
}
}
}
2.
/*
公司年销售额求和
某公司的月份统计
*/
class SumArray
{
public static void main(String[] args)
{
int[][] number ={{22,45,56},{43,56,34},{24,45,65},
{23,34,45}};
int sumMoney = 0;
for(int i = 0;i<number.length;i++)
{
int seasonMoney = 0;
for(int j =0;j< number[i].length;j++)
{
seasonMoney +=number[i][j];
if(j == number[i].length - 1)
{
System.out.println("the"+(i
int sumMoney = 0;
for(int i = 0;i<number.length;i++)
{
int seasonMoney = 0;
for(int j =0;j< number[i].length;j++)
{
seasonMoney +=number[i][j];
if(j == number[i].length - 1)
{
System.out.println("the"+(i
+1)+"season money is "+seasonMoney);
}
}
sumMoney += seasonMoney;
}
System.out.println("the sum money is "+sumMoney);
}
}
}
}
sumMoney += seasonMoney;
}
System.out.println("the sum money is "+sumMoney);
}
}
java的参数传递问题:
/*
思考题1:看程序写结果,然后分析为什么是这个样子的。并画图讲解。最
思考题1:看程序写结果,然后分析为什么是这个样子的。并画图讲解。最
后总结Java中参数传递规律。
Java中的参数传递问题:
基本类型:形式参数的改变对实际参数没有影响。
引用类型:形式参数的改变直接影响实际参数。
*/
class ArgsDemo {
public static void main(String[] args) {
int a = 10;
int b = 20;
System.out.println("a:"+a+",b:"+b); //a:10,b:20
change(a,b);
System.out.println("a:"+a+",b:"+b); //??? a:10,b:20
Java中的参数传递问题:
基本类型:形式参数的改变对实际参数没有影响。
引用类型:形式参数的改变直接影响实际参数。
*/
class ArgsDemo {
public static void main(String[] args) {
int a = 10;
int b = 20;
System.out.println("a:"+a+",b:"+b); //a:10,b:20
change(a,b);
System.out.println("a:"+a+",b:"+b); //??? a:10,b:20
int[] arr = {1,2,3,4,5};
change(arr);
System.out.println(arr[1]); //??? 4
}
change(arr);
System.out.println(arr[1]); //??? 4
}
public static void change(int a,int b) { //a=10,b=20
System.out.println("a:"+a+",b:"+b); //a:10,b:20
a = b; //a=20
b = a + b; //b=40
System.out.println("a:"+a+",b:"+b); //a:20,b:40
}
System.out.println("a:"+a+",b:"+b); //a:10,b:20
a = b; //a=20
b = a + b; //b=40
System.out.println("a:"+a+",b:"+b); //a:20,b:40
}
public static void change(int[] arr) { //arr={1,2,3,4,5};
for(int x=0; x<arr.length; x++) {
if(arr[x]%2==0) {
arr[x]*=2;
}
}
//arr={1,4,3,8,5};
}
}
for(int x=0; x<arr.length; x++) {
if(arr[x]%2==0) {
arr[x]*=2;
}
}
//arr={1,4,3,8,5};
}
}
//面向对象的开发,设计,特征
面向对象的开发:不断地创建对象
面向对象的设计:管理和维护对象间的关系
面向对象的特征:
封装,
继承
多态
类与对象的关系:
类是一个模板,对象是根据类产生的一个实际的物品
java中最基本的对象是类;
类是一个模板,对象是根据类产生的一个实际的物品
java中最基本的对象是类;
类:成员变量,成员方法
对象:属性,行为
对象:属性,行为
类是一组相关的属性和行为的集合;
对象是具体存在的
/*
创建一个学生类
并使用该类
*/
对象是具体存在的
/*
创建一个学生类
并使用该类
*/
class Student
{
String name;
int age;
char sex;
public void speak()
{
System.out.println("i am a student!");
}
public void run()
{
System.out.println("i can run ");
}
}
{
String name;
int age;
char sex;
public void speak()
{
System.out.println("i am a student!");
}
public void run()
{
System.out.println("i can run ");
}
}
class Demo
{
public static void main(String[] args)
{
Student jerry = new Student();
jerry.sex = 'b';
jerry.name = "kang";
jerry.run();
jerry.speak();
}
}
{
public static void main(String[] args)
{
Student jerry = new Student();
jerry.sex = 'b';
jerry.name = "kang";
jerry.run();
jerry.speak();
}
}
0 0
- java学习—day_6
- java中的数组day_6
- Day_6.
- 初学者的学习复习day_6
- Day_6重载
- Day_6.(2)
- Day_6.(3)
- ios--c DAY_6
- Practice Every Day_6 (Lucene 小练习)
- day_6-acm 二分查找+尺取法
- java学习笔记—
- java入门学习—
- java学习—day_1
- java学习—day_2
- java学习—day_3
- java学习—day_4
- java学习—day_5
- Java学习—类
- Duilib介绍以及各个类的简介
- IOS/Swift 通讯录步骤
- switch 中的return break
- 【HDU】 1242 Rescue
- tableview或者ScrollView看不到边界以外的内容
- java学习—day_6
- Centos下:/usr/bin/ld: cannot find -lXext
- float类型在值传递过程中出现的问题
- 项目管理十大知识范围
- poj 1611 The Suspects(并查集)
- 数据结构与算法学习
- 系统学习机器学习之参数方法(三)
- 网站开发进阶(二十九)HTML特殊转义字符
- 深度学习与计算机视觉系列(4)_最优化与随机梯度下降\数据预处理,正则化与损失函数