一个允许输出方在Java控制台 [英] Outputing a square to console in java

查看:134
本文介绍了一个允许输出方在Java控制台的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好我做了我的课程,我都被赋予的任务是使算法的正方形是采用5×5*,但必须与填写。所以像这样的:

Hi i am doing my coursework and i have been given the task is to make an algorithm for a square that's 5x5 using "*" but has to be filled in with "." so like this:

*****
*...*
*...*
*...*
*****

我已经使用这个code我知道它可能非常混乱,因为我是一位绝对的初学者到这个东西。我不能似乎得到了。在我目前有:

I have used this code I know its probably very messy because im an absolute beginner to this stuff. I cant seem to get the "." in i currently have:

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

这是我的code:

here is my code:

public static void main( String args[] )
{
    System.out.print ("#size of square");
    int stars=BIO.getInt();
    int j=1;
    while(j <= stars)
    {
        int starsNumber=1;
        while (starsNumber<= stars)
        {
            int i = 1;                        // Display trunk
            starsNumber=starsNumber+1;
            System.out.print('*');
        }
        System.out.println();

        j= j +1;
    }
}

PS对不起这么坏的编码:D和任何帮助将非常AP preciated感谢加雷斯

p.s sorry for been so bad at coding :D and any help would be much appreciated thanks Gareth

推荐答案

你得到的程序打印一个5×5平方全星号的工作?

Have you gotten the program to print an 5x5 square full of asterisks working?

我会强烈建议得到了工作的首位。在此之后,你只需要稍作修改,打印点之间。

I'd strongly recommend getting that working first. After that, you just need a minor modification to print the dots in between.

对于这一点,而不是总打印一个星号,你需要一个条件。

For that, instead of always printing an asterisk, you'll need a conditional.

伪code:

if(I'm currently on the edge)
  Print an asterisk
else
  Print a dot

我会离开它给你找出如何将其转换成真正的code。祝你好运!

I'll leave it to you to figure out how to translate this into real code. Good luck!

编辑,如何确定,如果你当前的边缘提示:

Edit, hints on how to determine if you're currently on the edge:

  1. 您正在跟踪当前行和当前列(以 打印方完全5x5的字符)。
  2. 的边缘由第一行和最后一行,以及第一个和最后一列。
  3. 有了一丝1和2的提示,你现在可以决定,当你在边缘,当你不?你需要做的变量比较,所以读课本,如果你不熟悉如何比较变数。
  1. You are keeping track of the current row and current column (in order to print a square exactly 5x5 characters).
  2. The edge consists of the first and last row, and the first and last column.
  3. Given hint 1 and hint 2, can you now determine when you are on the edge and when you're not? You'll need to do variable comparison, so read your textbook if you're not familiar with how to compare variables.

希望有所帮助。这确实不放弃确切的答案不是更多,我可以说。

Hope that helps. There's really not much more I can say without giving away the exact answer.

最后,想想你的解决方案的的编码它。立即跳进编码可能是一个障碍,尤其当你是一个初学者和不太熟悉的语言,所以你在语言的语法越陷越深。弱智放在一起你的程序的流程,画画,也许写假code你写的实际code之前。我发现,这样做可以帮助我写code更容易,减少错误所出现的次数。

Finally, think about your solution before coding it. Immediately jumping into coding can be a roadblock, especially when you're a beginner and not too familiar with the language so you get bogged down in the language syntax. Mentally put together the flow of your program, draw pictures, and maybe write pseudocode before you write the actual code. I find that doing this helps me write code easier and reduces the number of bugs that come up.

这篇关于一个允许输出方在Java控制台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆