谁能帮我?新手代码错误! [英] can anyone help me? newbie- code errors!

查看:60
本文介绍了谁能帮我?新手代码错误!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能帮助我吗?代码错误!

------------------------------------------ --------------------------------------


我正在为打印机创建代码。我想回答的问题是:


MyPrinter需要一些打印方法。第一个,签名:

public boolean printOne(String text){}

应该将String作为参数,并将它作为参数输出到终端窗口。

它还应该增加(加1)所制作的副本总数,并减少(减去1)可用纸张数量。

它应该返回布尔值true(这实际上是为了避免在下一个任务中出现混淆)

第二个,签名:

public void print5(String text){}

应该将String作为参数,并将其连续五行输出到终端窗口。

它还应该增加5个拷贝的总份数,并减少5个可用的页数。

它不应该返回任何东西。



这是我的编码。我一直得到无法接受的声明,我是一个新手,所以我真的不明白我做错了什么。


展开 | 选择 | Wrap | 行号

解决方案

1。)发布代码时使用代码标签

2.)您只能从方法返回一个值。如果在方法中遇到return语句,则在返回语句之后放置的任何代码都被视为无法访问,因为在找到返回时退出该方法。


抱歉今天再次发布,但我想弄清楚为什么我的代码不做我想要的。

我试图让代码在打印时从打印的纸张中添加1,从打印件中减去1。


这是我的代码一直在使用:

展开 | 选择 | Wrap | 行号



很抱歉今天再次发布,但我试图找出为什么我的代码不做我想要的。

我试图让代码在打印时从打印的纸张中添加1,从打印件中减去1。


这是我的代码一直在使用:


代码:(文本)

public boolean printOne(String text)

{

System.out.println(" Test printOne");

返回工作表==工资单 - 1;

}

public boolean PrintOne(String text)

{

返回打印==打印+ 1;

}


任何帮助将不胜感激


谢谢x



所以你的方法确实没有需要返回一个布尔值吗?并且不需要String文本参数,是吗?

您也可以在一个方法中同时更新工作表和打印变量。所以你只需要一种方法,对吗?


进行这些更改并在发现问题时回复。


can anyone help me? code errors!
--------------------------------------------------------------------------------

im creating a code for a printer. the question i am trying to answer is :

MyPrinter needs some printing methods. The first, signature:
public boolean printOne(String text) {}
should take a String as a parameter, and output it on a single line to the terminal window.
It should also increment (add 1 to) the total number of copies made, and decrement (subtract 1 from) the number of sheets of paper available.
It should return the boolean value true(this is actually to avoid confusion in the next assignment)
the second, signature:
public void print5(String text) {}
should take a String as a parameter and outputs it on five successive single lines to the terminal window.
It should also increase the total number of copies made by 5, and reduce the number of sheets available by 5.
It should not return anything.


this is my coding. i keep getting unreachable statement and im a newbie so i dont really understand what ive done wrong.


Expand|Select|Wrap|Line Numbers

解决方案

1.) Use code tags when posting code
2.) You can return only one value from a method. If a return statement is encountered in a method, any code that you put after that return statement is deemed unreachable because the method is exited when the return was found.


sorry to post again today, but im trying to figure out why my code isnt doing what i want.
Im trying to get the code to add 1 from sheets printed when a print has occured and minus 1 from prints available.

This is the code i have been using:


Expand|Select|Wrap|Line Numbers


sorry to post again today, but im trying to figure out why my code isnt doing what i want.
Im trying to get the code to add 1 from sheets printed when a print has occured and minus 1 from prints available.

This is the code i have been using:


Code: ( text )
public boolean printOne(String text)
{
System.out.println("Test printOne");
return sheets == sheets - 1;
}
public boolean PrintOne(String text)
{
return prints == prints + 1;
}


any help would be appreciated

thanks x

So your method really doesn''t need to return a boolean does it? And does not need the String text argument either, does it?
You can update both the sheets and prints variables all in one method too. So you just need one method, right?

Make these changes and post back if you still have problems.


这篇关于谁能帮我?新手代码错误!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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