我叫王超然,是一名电脑爱好者,现在在新加坡留学上高一.我立志成为一名电脑人才,愿意在这里与大家一同分享我玩转电脑的心得.O-level华文考了A-One哈哈!
天气: 晴朗
心情: 高兴
/*P3Q11
* Wang Chaoran
Description:(Finding numbers divisible by 5 or 6, but not both)
Write a program that displays all the numbers from 100 to 200,
ten per line, that are divisible by 5 or 6, but not both.
*/
public class P3Q11
{
public static void main(String[] args)
{
int count =0;
String output="";
//Calculate the numbers that are divisible by 5 or 6, but not both.
for(int i =100; i<201;i++)
{
if(i%5==0^i%6==0)
{
//Print the numbers 10 per line
output = output + i +" ";
++count;
if(count%10==0)
{
output =output+"\n";
}
}
}
//Print the output
System.out.println("All the numbers from 100 to 200,(that are divisible by 5 or 6, but not both): "+"\n"+output);
}
}
导入论坛查看(35)回复(0)引用(0)好评(0) 差评(0)
加入收藏
编辑
审核
TAG:
computing