星星模式程序 [英] Stars pattern program

查看:66
本文介绍了星星模式程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要程序提示用户输入3到79之间的奇数,然后输出将如下所示:


例如,如果他们输入5:

*

**

***

****

** ***


或9:

*

**

***

****

*****

******

***** **

********

*********

解决方案

< blockquote>这是我的第一次尝试:

展开 | 选择 | Wrap | 行号



这是我的第一次尝试:

展开 | 选择 | Wrap | 行号



你好,

首先看一下你的程序,我可以说你必须得到多个编译时错误!


-在main()之后给'';''?这将使它变得抽象,它的主体将被忽略。


-字符文字需要用单引号('''')括起来,而不是双引号("')。


-方法readLine()能够抛出''IOException''。这种异常是''Java Checked Exception'',必须处理这种类型的异常在try-catch块中或声明被抛出。


- for(num1 == 1)不正确。

''==''是比较和''=''用于分配。


''for''循环的结构是:

for(初始化;终止;增量)$

语句

}

for循环的第一个表达式用于初始化,但是如果你执行比较你肯定会收到错误。


-num3< 80?

什么是num3?它在哪里宣布?


- Java中没有do循环,w的循环我们有同时做的事情。


请编译你的程序并仔细查看你得到的例外情况,先尝试逐一排序。如果你不明白发布任何异常。


至于逻辑:

说有3行然后 -

第1行:一个*

第2行:两个*

第3行:三个*

查看行号和相应星号之间的连接。

现在概括它。



是的,我在发布后意识到我犯了很多错误。这是我现在拥有的

展开 | 选择 | Wrap | 行号


I need the program to prompt the user to input an odd number between 3 and 79 and then the output will look like this:

for example if they input 5:
*
**
***
****
*****

or 9:
*
**
***
****
*****
******
*******
********
*********

解决方案

here is my first attempt:

Expand|Select|Wrap|Line Numbers


here is my first attempt:

Expand|Select|Wrap|Line Numbers


Hello,
First of all taking one look at your program I can say you must be getting more than a few compile time errors!

-Giving a '';'' after main()? That will make it abstract and its body will be ignored.

-A character literal needs to be enclosed in single quotes('' '') not double(" ").

-The method readLine() is capable of throwing an ''IOException''.This exception is a type of ''Java Checked Exception'', such type of exceptions must be handled in a try-catch block or declared to be thrown.

- for(num1 == 1) is incorrect.
''=='' is for comparision and ''='' is for assignment.

Structure of a ''for'' loop is :
for (initialization; termination; increment) {
statement(s)
}
The first expression of the for loop is for initialization, but instead if you carry out comparision you''ll definitely get an error.

-num3<80 ?
What is num3?Where is it declared?

- There is no do-loop in Java, the loops that we have are for,while,do-while.

Please compile your program and take a good look at the exceptions you are getting, try to sort them out one by one first. If you don''t understand any exception post it.

As for the logic:
say there are 3 lines then -
line 1: one *
line 2: two *''s
line 3: three *''s

See the connection between the line number and the corresponding number of stars in it.
Now generalize it.

Yeah I realized after posting I made a ton of errors. Here is what I have now

Expand|Select|Wrap|Line Numbers


这篇关于星星模式程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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