public class Test{ public static void main(String[] args) { for(int i=1;i<10;i++){ for(int j=1;j<=10-i;j++){ System.out.print(" "); } for(int j=1;j<=2*i-1;j++){ System.out.print("*"); } System.out.println(""); } } }代码给你了,自己思考一下为什么做不出,为什么不能和同学交流?为什么不能问问老师?
public class Test{ public static void main(String[] args) { System.out.println(" *\n ***\n *****\n*******"); } }
import java.awt.Color; import java.awt.Frame; import java.awt.Graphics;public class Arc extends Frame{ private static final int width = 800; private static final int height = 800;
@Override public void paint(Graphics g) { Color c = g.getColor(); g.setColor(Color.ORANGE); int h = (int)Math.round((float)200*Math.sqrt(3)); int x2 = 300; int y2 = 100 + h; g.drawLine(100, 100, 500, 100); g.drawLine(100, 100, x2, y2); g.drawLine(500, 100, x2, y2); g.setColor(c); } public void launchFrame() { this.setBackground(Color.BLACK); this.setBounds(0, 0, width, height); this.setResizable(false); this.setVisible(true); } public static void main(String[] args) { Arc aric = new Arc(); aric.launchFrame(); } }哎呀,现在这学生...
说白了就是杨辉三角,14楼给的是等腰的。public class YangHuiTriangle { public static void main(String[] args) { triangle(5); } public static int[][] triangle(int n) { int[][] yh = new int[n][n]; for (int i = 0; i <= n-1; i++) { for (int j = n; j >= 0; j--) { System.out.print(" "); if (i >= j) { if (i == 0 || j == 0) { yh[i][j] = 1; System.out.print(yh[i][j]); } else { yh[i][j] = yh[i - 1][j - 1] + yh[i - 1][j]; System.out.print(yh[i][j]); } } } System.out.println(); } return yh; } }
public class Test { public static void main(String []args) { int x; int y; int z; for(z = 1; z <= 8; z++) { for(y = z; y < 8; y++) { System.out.print(" "); } for(x = 1; x <= 8; x++) { if(x<=z) { System.out.print("*"); } } for(x = 2; x <= 8; x++) { if(x <= z) { System.out.print("*"); } } System.out.println(""); } } }小弟新手,请大侠们帮看看是否可以再优化一下?
public class GetCurrentPath { public static void main(String[] args){ final int LEN = 10; char[][] triangle = new char[5][LEN]; int j=0; for(int i=triangle.length-1;i>=0;i--){
public class Test{
public static void main(String[] args) {
for(int i=1;i<10;i++){
for(int j=1;j<=10-i;j++){
System.out.print(" ");
}
for(int j=1;j<=2*i-1;j++){
System.out.print("*");
}
System.out.println("");
}
}
}代码给你了,自己思考一下为什么做不出,为什么不能和同学交流?为什么不能问问老师?
public static void main(String[] args) {
System.out.println(" *\n ***\n *****\n*******"); }
}
import java.awt.Color;
import java.awt.Frame;
import java.awt.Graphics;public class Arc extends Frame{
private static final int width = 800;
private static final int height = 800;
@Override
public void paint(Graphics g) {
Color c = g.getColor();
g.setColor(Color.ORANGE);
int h = (int)Math.round((float)200*Math.sqrt(3));
int x2 = 300;
int y2 = 100 + h;
g.drawLine(100, 100, 500, 100);
g.drawLine(100, 100, x2, y2);
g.drawLine(500, 100, x2, y2);
g.setColor(c);
}
public void launchFrame() {
this.setBackground(Color.BLACK);
this.setBounds(0, 0, width, height);
this.setResizable(false);
this.setVisible(true);
} public static void main(String[] args) {
Arc aric = new Arc();
aric.launchFrame();
}
}哎呀,现在这学生...
public static void main(String[] args) {
triangle(5);
} public static int[][] triangle(int n) {
int[][] yh = new int[n][n];
for (int i = 0; i <= n-1; i++) {
for (int j = n; j >= 0; j--) {
System.out.print(" ");
if (i >= j) {
if (i == 0 || j == 0) {
yh[i][j] = 1;
System.out.print(yh[i][j]);
} else {
yh[i][j] = yh[i - 1][j - 1] + yh[i - 1][j];
System.out.print(yh[i][j]);
}
}
}
System.out.println();
}
return yh;
}
}
{
public static void main(String []args)
{
int x;
int y;
int z;
for(z = 1; z <= 8; z++)
{
for(y = z; y < 8; y++)
{
System.out.print(" ");
}
for(x = 1; x <= 8; x++)
{
if(x<=z)
{
System.out.print("*");
}
}
for(x = 2; x <= 8; x++)
{
if(x <= z)
{
System.out.print("*");
}
}
System.out.println("");
}
}
}小弟新手,请大侠们帮看看是否可以再优化一下?
public static void main(String[] args){
final int LEN = 10;
char[][] triangle = new char[5][LEN];
int j=0;
for(int i=triangle.length-1;i>=0;i--){
for(int m=0;m<j;m++){
triangle[i][m] = ' ';
}
int perRowLast = triangle[i].length-1-j;
for(int m=j;m<=perRowLast;m++){
triangle[i][m++] = '*';
if(m>perRowLast){
break;
}
triangle[i][m] = ' ';
}
for(int m=perRowLast+1;m<triangle[i].length;m++){
triangle[i][m] = ' ';
}
j++;
}
System.out.println("---------------split line-----------------");
for(int p=0;p<triangle.length;p++){
for(int q=0;q<triangle[p].length;q++){
System.out.print(triangle[p][q]);
}
System.out.println();
}
System.out.println("---------------split line-----------------");
}
}
---------------split line-----------------
*
* *
* * *
* * * *
* * * * *
---------------split line-----------------
char[][] triangle = new char[(LEN+1)/2][LEN];