首页 > 编程知识 正文

java星号拼字,Java中 星号这怎么打

时间:2023-12-28 11:57:09 阅读:328364 作者:UDHC

本文目录一览:

在java中编一个可以输出星号金字形状的程序,挂上详解!重谢

用星号来打印金字塔,有一定的规律:

1、中心对齐;

2、从上往下,每一层的星星个数都是奇数,而且每一层星星数量可以用以下公式来计算:2*n-1;

3、每一层前面都会出现空位,前面的空位数为当前层数减1,即满足公式:n-1

根据上述规律,我们得出如下算法:

public void testKing() {

// 定义金字塔层数

int n = 7; 

for (int i = 1; i = n; i++) {

// 第一层循环,打印出对应的层数

for (int k = 1; k = n - i; k++) {

// 本层循环,打印出当前层的空位

// 空位数为当前层数减1,即满足公式:n-1

System.out.print(" ");

}

for (int j = 1; j = 2 * i - 1; j++) {

// 本层循环,打印出当前层的星星个数

// 每一层的星星个数都是奇数,且数量可以用以下公式来计算:2*n-1

System.out.print("*");

}

// 打印出一个换行

System.out.println(); 

}

}

结果示例:

      *

     ***

    *****

   *******

  *********

 ***********

*************

用java输出星号

我用了另一种方法来做,但输出的效果是一样的public static void main(String[] args) {

int i,j;

for(i=0;i3;i++)

{

for(j=0;j3-i;j++)System.out.print(" ");

for(j=0;j=i;j++)System.out.print("* ");

System.out.print("n");

}

}运行的结果图如下

java输出星号如图 * *** ***** ******* *******

    public static void main(String[] args) {

        int[][] snow = new int[5][];

        for(int i = 0; i  snow.length; i++)

            snow[i] = new int[i*2+1];

        for(int i = 0; i  snow.length; i++) {

            for(int j = 0; j  snow[i].length; j++) {

                snow[i][j] = '*';

            }

        }

        int n = 1;

        for(int i = 0; i  snow.length; i++) {

            for(int k = 0; k  snow.length - n; k++) {

                System.out.print(" ");

            }

            for(int j = 0; j  snow[i].length; j++)

                System.out.print((char)snow[i][j]);

            System.out.println();

            ++n;

        }

    }

应该很标准了吧...

java拼字游戏(1组10个字母中至少2个原音字母,可重复字母)拼对得分 拼错换人..

可能不符合要求,自己看吧

import java.io.BufferedReader;

import java.io.FileReader;

import java.io.IOException;

import java.util.ArrayList;

import java.util.Random;

import java.util.Scanner;

public class Words {

private static char[] consonant={'B','C','D','F','G','H','J','K','L','M','N','P','Q',

'R','S','T','V','W','X','Y','Z'};

private static char[] vowel={'A','E','I','O','U'};

private static ArrayListString dict = new ArrayListString();

public static void main(String[] args) throws IOException {

// TODO Auto-generated method stub

getResource();

int score1 = 0;

int score2 = 0;

Scanner userInput = new Scanner(System.in);

String A= null;

int count = 0;

boolean flag = false;//true 为Player1, FALSE为Player2

do{

String random = randomString();

System.out.println(random);

if(flag)

{

System.out.println("Player1 input a word: (or ‘@’ to pass or ‘!’ to quit)");

A=userInput.nextLine();

if(A.equals("@") )

{

flag =!flag;

System.out.println("Player2 input a word: (or ‘@’ to pass or ‘!’ to quit)");

A =userInput.nextLine();

}

}

else

{

System.out.println("Player2 input a word: (or ‘@’ to pass or ‘!’ to quit)");

A=userInput.nextLine();

if(A.equals("@") )

{

flag = !flag;

System.out.println("Player1 input a word: (or ‘@’ to pass or ‘!’ to quit)");

A =userInput.nextLine();

}

}

if(A.equals("@"))

{

System.out.println("反复切换,系统退出");

return;

}

else

{

String temp = null;

if(flag)

{

//String random = randomString();

temp = match(random,A);

if(find(temp,dict))

score1+=2;

System.out.println(" Player1 get "+score1+" points");

}

else

{

//String random = randomString();

temp = match(random,A);

if(find(temp,dict))

score2+=2;;

System.out.println(" Player2 get "+score2+" points");

}

}

count++;

}while(count 10(!A.equals("!")));

System.out.println("游戏结束!");

System.out.println("Player1 get"+score1+"points");

System.out.println("Player2 get"+score2+"points");

if(A.equals("!") )

System.out.println("exit");

}

public static String randomString()//产生随机字符串

{

Random generator = new Random();

String temp = new String();

for(int i = 0;i8;i++)

temp += consonant[generator.nextInt(20)+1];

temp+=vowel[generator.nextInt(4)+1];

temp+=vowel[generator.nextInt(4)+1];

return temp;

}

public static String match(String str1,String str2)//

{

if(str1.contains(str2))

{

System.out.println("Bingo,you get it!");

return str2;

}

else

{

String temp = new String();

L1: for(int i = 0;istr2.length();i++)

{

for(int j = 0;jstr1.length();j++)

if(str2.charAt(i)==str1.charAt(j))

{

temp += str2.charAt(i);

continue L1;

}

}

return temp;

}

}

public static boolean find(String str,ArrayListString soure)//从读取的信息中查找输入的字符串

{

for(int i = 0;i soure.size();i++)

{

if(soure.get(i).equals(str))

{

System.out.println("Find It ! You can get two points");

return true;

}

}

return false;

}

public static void getResource() throws IOException//读取words.txt文件

{

FileReader fin = new FileReader("words.txt");

BufferedReader bin = new BufferedReader(fin);

String str = null;

do{

str = bin.readLine();

if(str!=null)

dict.add(str);

}while(str!=null);

bin.close();

fin.close();

}

}

Java控制台输出由星号组成的国字

System.out.println("*********");

System.out.println("* ***** *");

System.out.println("*   *   *");

System.out.println("*  ***  *");

System.out.println("*   * * *");

System.out.println("* ***** *");

System.out.println("*********");

java:用星号输出汉字 文

1.自己在本子上画出一个表格,通过描黑其中部分单元格来形成一个字。 2.记录每个描黑点的位置,记录方式如下。“1-3” “2-5” 第一个数组是行数,第二个数字为第几列。 讲记录的数组输入到程序中。或者自己定义一个文件,按照一定的格式记录黑点的位置,输入的文件中。 3.java程序负责初始化的时候加载黑点位置。用java二维数组来表示一个表格,数组中每个值如果为0是没有描黑的,如果为1是描黑的。 4.便利这个数组输出。遇到0输出“☆”。遇到1输出“★”。

麻烦采纳,谢谢!

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。