t;< "* ";
}
cout << endl;
}
}
给出全部代码:
#include <iostream>
using namespace std;
/**
* 定义一个类
*/
class Location {
private:
int x; // 横坐标
int y; // 纵坐标
public:
Location() {
}
Location(int x, int y) {
this->x = x;
this->y = y;
}
int getX() {
return x;
}
void setX(int x) {
this->x = x;
}
int getY() {
return y;
}
void setY(int y) {
this->y = y;
}
};
// 声明函数
inline void print(int x, int y);
int main() {
// 声明
Location location;
cout << "输入X坐标:\t";
int x;
cin >> x;
location.setX(x);
cout << "输入Y坐标:\t";
int y;
cin >> y;
location.setY(y);
cout << "X坐标是:\t" << location.getX() << endl;
cout << "Y坐标是:\t" << location.getY() << endl;
// 做倒三角打印
print(x, y);
return 0;
}
/**
* 倒三角打印
*/
inline void print(int x, int y) {
int i;
for (i = 0; i < y; i++) {
cout << i + 1 << "\t";
int j;
for (j = i; j < x; j++) {
cout << "* ";
}
cout << endl;
}
}
?§1yJavaμ?è???μ?oü±e?¤?£o?o?£??òò2ò??ù?£
×?oó£?è??ò???′?′?a2??3ìDòμ?×???ê?3?£o
console′ú??
ê?è?X×?±ê£o?? 9
ê?è?Y×?±ê£o?? 9
X×?±êê?£o???? 9
Y×?±êê?£o???? 9
1???? * * * * * * * * *
2???? * * * * * * * *
3???? * * * * * * *
4???? * * * * * *
5???? * * * * *
6???? * * * *
7???? * * *
8???? * *
9???? *
??3éJavaêμ??£o
Java′ú??£o
import javax.swing.JOptionPane;
public class Location {
?????? private int x;
?????? private int y;
?????? /**
???????? * @return the x
???????? */
?????? public int getX() {
?????????????? return x;
?????? }
?????? /**
???????? * @param x
???????? *?????????????????????? the x to set
???????? */
?????? public void setX(int x) {
?????????????? this.x = x;
?????? }
?????? /**
???????? * @return the y
???????? */
?????? public int getY() {
?????????????? return y;
?????? }
?????? /**
???????? * @param y
???????? *?????????????????????? the y to set
???????? */
?????? public void setY(int y) {
?????????????? this.y = y;
?????? }
?????? /**
???????? * @param args
???????? */
?????? public static void main(String[] args) throws Exception {
?????????????? Location location = new Location();
?????????????? int x = Integer.parseInt(JOptionPane.showInputDialog("ê?è?X×?±ê£o"));
?????????????? int y = Integer.parseInt(JOptionPane.showInputDialog("ê?è?Y×?±ê£o"));
?????????????? location.setX(x);
?????????????? location.setY(y);
?????????????? locati
|