用java语言写一个方法输出以下的图形第一行*.第二行*..*...第三行*...*...*...,依次类推public class Star {/*** @param args*/public static void main(String[] args) {// TODO Auto-generated method stubScanner s = new Scanner(Syste
来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/17 04:49:55
用java语言写一个方法输出以下的图形第一行*.第二行*..*...第三行*...*...*...,依次类推public class Star {/*** @param args*/public static void main(String[] args) {// TODO Auto-generated method stubScanner s = new Scanner(Syste
用java语言写一个方法输出以下的图形第一行*.第二行*..*...第三行*...*...*...,依次类推
public class Star {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner s = new Scanner(System.in);
String num = s.nextLine();
int number = Integer.parseInt(num);
Star star = new Star();
star.fun(number);
}
public void fun(int i) {
for (int j = 0; j 0) {
System.out.print("*");
}
for (int k = j; k < i; k++) {
System.out.print(".");
}
}
System.out.println();
}
}
}
这是我写的代码,但是输出来的图形是
*.*.*.*.
*...*...*...
*..*..
*.
,如何输出正着的图形?
用java语言写一个方法输出以下的图形第一行*.第二行*..*...第三行*...*...*...,依次类推public class Star {/*** @param args*/public static void main(String[] args) {// TODO Auto-generated method stubScanner s = new Scanner(Syste
public class ShortTest {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
String num = s.nextLine();
int number = Integer.parseInt(num);
ShortTest.printDiagram(number);
}
public static void printDiagram(int i){
for (int le=0;le<=i;le++){
for(int j=0;j<le;j++){
System.out.print('*');
for (int k=0;k<le;k++)
System.out.print('.');
}
System.out.println();
}
}
}
输入4,打出来
*.
*..*..
*...*...*...
*.*.*.*.