******      ******
 *****      *****
  ****      ****
   ***      ***
    **      **
     *      *     *      *
    **      **
   ***      ***
  ****      ****
 *****      *****
******      ******
cmd里显示这种形式的蝴蝶文怎么写啊?显示的时候是用无限循环显示“*”增加,等摁回车的时候停止继续扩展
小弟初学java 请高手多多指点。先谢谢各位了。

解决方案 »

  1.   

    ButterFlyStar.java
    /**
     *
     * @author zdjray
     */
    public class ButterFlyStar {    public void print() throws InterruptedException {
            boolean flag = true;
            int count = 6;
            while (true) {
                for (int i = 0; i < 6 - count; i++) {
                    System.out.print(" ");
                }
                for (int i = 0; i < count; i++) {
                    System.out.print("*");
                }
                System.out.print("\t");
                for (int i = 0; i < count; i++) {
                    System.out.print("*");
                }
                System.out.println();            count += flag ? (-1) : 1;
                if (count >= 6) {
                    flag = true;
                }
                if (count <= 0) {
                    flag = false;
                }
                Thread.sleep(300);
            }
        }
    }Main.java
    /**
     *
     * @author zdjray
     */
    public class Main {    /**
         * @param args the command line arguments
         */
        public static void main(String[] args) throws InterruptedException {
            // TODO code application logic here
            ButterFlyStar star = new ButterFlyStar();
            star.print();
        }}命令行运行时,要停止直接ctrl+c就可以了
    至于回车的部分自己实现吧:)
      

  2.   

    试试这个是不是你要得,在eclipse下运行时,把光标放到控制台上,然后点回车就可以了.
    在CMD上没试,你试试吧.
    import java.io.IOException;public class Butterfly extends Thread{ public static int er = 0;//停止标记
        private int count = 1;//记录*数
        
    public void run() {
    System.out.print('*');
    while(true){
    if(er == 10){
    this.stop();
    }
    count++;
    System.out.print('*');
    try {
    Thread.sleep(200);
    } catch (InterruptedException e) {
    System.out.println("//Thread.sleep(200);抛出异常!");
    e.printStackTrace();
    }
    }
    }
    //输出一串"*"
    public void printStarLine(int count){
    for(int i = 0 ;i < count ; i++)
    System.out.print('*');
    }
    //控制输出
    public void printButterfly(){

    if(count/2 != 0){
    count++;
    }

    for(int i = 0 ;i < count/2 + 1 ;i++){
    printStarLine(count - i*2);
    System.out.print(' ');
    printStarLine(count - i*2);
    System.out.println();
    }
    System.out.println();
    for(int i = count/2 + 1 ;i >= 0 ;i--){
    printStarLine(count - i*2);
    System.out.print(' ');
    printStarLine(count - i*2);
    System.out.println();
    }

    }

    public static void main(String[] args) {
    Butterfly bf = new Butterfly();
    bf.start();
    try {
    er = (int)System.in.read();
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    bf.printButterfly(); }}
      

  3.   

    修改了一下
    主要修改了
    if(count/2 != 0.0){
    count++;
    }
    System.out.println();
    System.out.println();
    其它不变package base;import java.io.IOException;public class Butterfly extends Thread{ public static int er = 0;//停止标记
        private int count = 1;//记录*数
        
    public void run() {
    System.out.print('*');
    while(true){
    if(er == 10){
    this.stop();
    }
    count++;
    System.out.print('*');
    try {
    Thread.sleep(200);
    } catch (InterruptedException e) {
    System.out.println("//Thread.sleep(200);抛出异常!");
    e.printStackTrace();
    }
    }
    }
    //输出一串"*"
    public void printStarLine(int count){
    if(count == 0)
    count = 1;
    for(int i = 0 ;i < count ; i++)
    System.out.print('*');
    }
    //控制输出
    public void printButterfly(){

    if(count/2 != 0.0){
    count++;
    }
    System.out.println();
    System.out.println();
    for(int i = 0 ;i < count/2 + 1 ;i++){
    printStarLine(count - i*2);
    System.out.print(' ');
    printStarLine(count - i*2);
    System.out.println();
    }
    for(int i = count/2 + 1 ;i >= 0 ;i--){
    printStarLine(count - i*2);
    System.out.print(' ');
    printStarLine(count - i*2);
    System.out.println();
    }

    }

    public static void main(String[] args) {
    Butterfly bf = new Butterfly();
    bf.start();
    try {
    er = (int)System.in.read();
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    bf.printButterfly(); }}