Plain's Blog

休想打败我的生活🔥

  • 1.1 输入一个数,打印出乘法表
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/*
*Persion类
*/

package com.tech.demo;

/**
* Created by value on 2018/9/8.
*/
public class Persion {

public void cfb(int a){
for (int i = 1;i<=a;i ++){
for (int j = 1;j<=i;j++){
System.out.print(i+ "*" + j + "=" + (i * j) + "\t");
}
System.out.println();
}
}
}

/*
*main
*/

public class main {
public static void main(String [] args){
Cat cat = new Cat();
Persion persion = new Persion();
persion.cfb(cat.putText());//把Scanner函数写到Cat类的putText方法中了
}
}

运行结果
QQ20180909-163711.png

  • 1.2 给定一个2位数组并转置输出
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
*Persion类
*/
package com.tech.demo;

public class Persion {
public void array(int[][] arr) {
System.out.println("转置前");

for (int i = 0; i <= (arr.length - 1); i++) {
for (int j = 0; j <= (arr.length - 1); j++) {
System.out.print(arr[i][j] + " ");
}

System.out.println();
}

System.out.println("转置后");

for (int i = 0; i <= (arr.length - 1); i++) {
for (int j = 0; j <= i; j++) {
int temp;
temp = arr[i][j];
arr[i][j] = arr[j][i];
arr[j][i] = temp;
}
}

/*
*输出
*/
for (int i = 0; i <= (arr.length - 1); i++) {
for (int j = 0; j <= (arr.length - 1); j++) {
System.out.print(arr[i][j] + " ");
}

System.out.println();
}
}
}

public class main {
public static void main(String[] args) {
Persion persion = new Persion();

int[][] array = {
{ 1, 2, 3 },
{ 4, 5, 6 },
{ 7, 8, 9 }
};
persion.array(array);
}
}

运行结果
QQ20180909-164041.png

  • 1.3 指定@符号出现在给定的坐标
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
*Ma类
*/

package com.tech.demo;

/**
* Created by value on 2018/9/9.
*/
public class Ma {

public void showImage(int a,int x,int y){
for (int i = 0;i<a;i ++){
for (int j = 0; j <a; j ++){
if (i == x && j == y){
System.out.printf("@" + " ");
}else {
System.out.printf("*" + " ");
}
}
System.out.println();
}
}

}

/*
*main函数
*/

package com.tech.demo;


/**
* Created by value on 2018/9/7.
*/

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

Ma ma = new Ma();
ma.showImage(10,5,8);//10*10矩阵,在(5,8)处显示@
}
}

运行结果
QQ20180909-171017.png

本文作者 : Plain
This blog is under a CC BY-NC-SA 3.0 Unported License
本文链接 : https://plain-dev.com/java-member-methods-of-the-class/

本文最后更新于 天前,文中所描述的信息可能已发生改变