返回信息流很白痴的题 大家不要做错了 哈哈
编写一个循环,循环变量从1到1000,当循环变量能被3整除时输出“etone”,当能被5整除时输出“tech”,当能同时被3和5整除时输出“etonetech”。
有兴趣的同学可以贴一下代码,回头我会发出总结
这是一条镜像帖。来源:北邮人论坛 / soft-design / #26295同步于 2008/6/11
该镜像源已超过 30 天没有更新,可能在源站已被删除。
SoftDesign机器人发帖
[坑] 大家来做题 C/C++/Java/各种脚本
coolfantasy
2008/6/11镜像同步78 回复
订阅后,新回复会通过你的通知中心匿名送达。
9 条回复
先说说坑在哪省得绊倒……
【 在 coolfantasy (Cool) 的大作中提到: 】
: 很白痴的题 大家不要做错了 哈哈
: 编写一个循环,循环变量从1到1000,当循环变量能被3整除时输出“etone”,当能被5整除时输出“tech”,当能同时被3和5整除时输出“etonetech”。
很没有难度
// Java
public static void main(String[] args) {
String three = "cool";
String five = "bc";
String fifteen = "coolbc";
int[] values = { 3, 5, 6, 9, 10, 12, 15 };
String[] strs = { three, five, three, three, five, three, fifteen };
int max = values[values.length - 1];
int n = 20;
int count = n / max;
int rest = n % max;
for (int i = 0; i < count; ++i) {
for (String str : strs) {
System.out.println(str);
}
}
for (int i = 0; i < values.length; ++i) {
if (rest >= values[i]) {
System.out.println(strs[i]);
} else {
break;
}
}
}
【 在 NWN2 的大作中提到: 】
: 很没有难度
: // Java
: public static void main(String[] args) {
: ...................
呃,弱弱地问一下,是不是这样啊
//C#
static void Main(string[] args)
{
for(int i=15;i<=1000;i+=15)
{
Array.ForEach(new string[] { "cool", "bc", "cool", "cool", "bc", "cool", "coolbc" }, Console.WriteLine);
}
Array.ForEach(new string[] { "cool", "bc", "cool", "cool", "bc" }, Console.WriteLine);
}