【发布时间】:2015-08-29 03:41:20
【问题描述】:
我是 Java 编程的新手,所以我希望你们中的任何人都可以帮助我。
这个问题让你用一个循环练习。
(a) 编写一个程序 OddSequencer.java,使用 for 循环打印以下系列 1 2 4 7 11 16。提示:首先识别此序列中的模式。特别是这个序列中连续的两个数有什么区别?
对不起,我不是想把它扔给你们。我知道对于 (a) 部分,数字系列中有一个模式,它从 1 (1+1) -> 2 (2+2) -> 4 (4+3) -> 7 (7+4) ) -> 11 (11+5) -> 16
我现在拥有的是
public class OddSequencer {
public static void main(String [] args){
for(int i = 1; i <= 16; i) // i'm not sure what the last condition is supposed to be
System.out.println(i);
}
}
(b) 编写一个名为 SumLoops.java 的程序,其 main 方法使用 for 循环打印从 3 到 30(包括 3 和 30)的 3 的倍数之和。
我现在拥有的是
public class SumLoops {
public static void main(String [] args){
for(int i = 3; i <= 30; i+=3)
System.out.println(i);
}
}
你的程序的输出应该是这样的:
D:\is200\lab1>java SumLoops
Sum of multiples of 3 from 3 to 30 = 165
D:\is200\lab1>
【问题讨论】:
-
"i was hoping if any of you could help me with this."不是一个具体的可回答问题,相反,您需要提出一个实际的具体问题,而不仅仅是将您的作业交给我们做。请查看help center 和how to ask good questions 部分,了解有关如何改进您的问题并增加获得体面帮助的机会的更多信息。 -
你有一些代码要显示吗?
-
不要在 cmets 中发布这些内容,而是请edit 并改进您的问题。多一点努力可以走很长的路。
-
如果我激怒了你们中的任何人,我很抱歉。