怎么將直角的變成等腰三角形三角形
public class HelloWorld {
? ? public static void main(String[] args) {
? ? ? ??
System.out.println("打印直角三角形");
? ? ? ??
// 外層循環(huán)控制行數(shù)
for (int i = 1; ?i<=3; i++) {
? ? ? ? ? ??
// 內(nèi)層循環(huán)控制每行的*號(hào)數(shù)
// 內(nèi)層循環(huán)變量的最大值和外層循環(huán)變量的值相等
for (int j = 1; ?j<=i ?; j++ ) {
? ? ? ? ? ? ? ??
System.out.print("*");
}
? ? ? ? ? ??
// 每打印完一行后進(jìn)行換行
System.out.println();
}
}
}
2016-03-16
public class HelloWorld {
? ? public static void main(String[] args) {
? ? ? ? System.out.println("打印等腰三角形");
? ? ? ? // 外層循環(huán)控制行數(shù)
? ? ? ? for (int i = 1; ?i<=3; i++) {
? ? ? ? for (int j = 1; ?j<=(3-i) ?; j++ ) {
? ? ? ? ? ? ? ? System.out.print(" ");
? ? ? ? ? ? ? ? }??
? ? ?// 內(nèi)層循環(huán)控制每行的*號(hào)數(shù)
? ? ? ? for(int k=(4-i);k<=(i+2);k++){
? ? ? ? System.out.print("*");
? ? ? ? ? ?}
? ? ? ? ? ? // 每打印完一行后進(jìn)行換行
? ? ? ? System.out.println();
? ? ? ? }
? ? ? ? }
? ? }
2016-04-24
public class HelloWorld {
? ? public static void main(String[] args) {
? ? ? ? System.out.println("打印等腰三角形");
? ? ? ? for(int i=1;i<=3;i++){
? ? ? ? ? ? for(int j=1;j<=3-i;j++){
? ? ? ? ? ? ? ? System.out.print(" ");
? ? ? ? ? ? }
? ? ? ? ? ? ? ? for(int k=1;k<=2*i-1;k++){
? ? ? ? ? ? ? ? ? ? System.out.print("*");
? ? ? ? ? ? ? ? }
? ? ? ? ? ? System.out.println();
? ? ? ? }
? ? }
}
2016-03-21
System.out.println("打印等邊三角形:");
for(int i = 1; i <=3; i++){
for(int j = i; j <= 2; j++){
System.out.print(" ");
}
for(int k = 1;k <= i; k++){
System.out.print(" *");
}
System.out.println();
}
2016-03-21
我試了下可以,但是思路還是很不清晰,誰可以解釋下嗎,特別是j<=3-i,后面
? ? ? ? System.out.print("*");
? ? ? ? System.out.print(" ")
還有這兩個(gè)的意思是先輸出*在輸出空白循環(huán)嗎,不太理解
2016-03-17
這是等邊的:
public class HelloWorld {
? ? public static void main(String[] args) {
? ? ? ? System.out.println("打印等邊三角形");
? ? ? ? // 外層循環(huán)控制行數(shù)
? ? ? ? for (int i = 1; ?i<=3; i++) {
? ? ? ? for (int j = 1; ?j<=3-i ; j++ ) {
? ? ? ? ? ? ? ? System.out.print(" ");
? ? ? ? ? ? ? ? } ?
? ? ?// 內(nèi)層循環(huán)控制每行的*號(hào)數(shù)
? ? ? ? for(int k=1;k<=i;k++){
? ? ? ? System.out.print("*");
? ? ? ? System.out.print(" ");
? ? ? ? ? ?}
? ? ? ? ? ? // 每打印完一行后進(jìn)行換行
? ? ? ? System.out.println();
? ? ? ? }
? ? ? ? }
? ? }
2016-03-16
public class HelloWorld {
? ? public static void main(String[] args) {
for (int i = 1; i<=3 ?;i++ ? ? ? ? ? ) {//控制行數(shù) ?
? ? ? ? ? ??
for (int a = 3; a>i ?; ?a-- ? ? ? ?) {//控制空白
? ?System.out.print(" ");
}
for (int j = 1; j<=i ?; ?j++ ? ? ? ?) {//控制* ?
? ? ? ? ? ? ? ??
System.out.print(" *");
}
? ? ? ? ? ??
System.out.println();
}
}
}
2016-03-16
public class HelloWorld{
? ? public static void main(String[] args) {
for(int i=1;i<=3;i++){
for(int k=1;k<=3-i;k++){
System.out.print(" ");
}
for(int j=1;j<=2*i-1;j++){
System.out.print("*");
}
System.out.println("");
}
}
}