
1.计算1+2+3+…+99的和
思路:余2等于0的是偶数,去除掉就可得到奇数
public class Test1{
public static void main(String [] args){
//声明1到100奇数和的变量sum
int sum = 0;
for(int i=1;i<p>免费教学视频分享:<a href="https://www.php.cn/course/list/36.html" target="_blank">java学习</a></p><p>2.读入一个小于10的整数n,输出它的阶乘</p><p>思路:乘法和加法一样,j = i</p><pre class="brush:php;toolbar:false">public class Test2{
public static void main(String [] args){
Scanner input = new Scanner(System.in);
System.out.println("输入小于10的整数n" );
//用户输入小于10的整数n
int n = input.nextInt();
//声明循环的变量i
int i ;
//声明阶乘的的结果为变量j
int j = 1;
if(n>0){
for(i=1;i<p>3.求100以内所有能被3整除,但不能被5整除的数字之和</p><p>思路:循环和选择判断的结合</p><pre class="brush:php;toolbar:false">public class Test3{
public static void main(String [] args){
//声明和的变量sum
int sum = 0;
for(int i = 1;i<p>4.“百钱买百鸡”是我国古代的著名数学题</p><p>3文钱可以买一只公鸡,2文钱可以买1只母鸡,1文钱可以买3只小鸡。用100文钱买100只鸡,可以买公 鸡、母鸡、小鸡各多少只?</p><p>思路:先理解题意,嵌套循环,当公鸡买(1-100/3)只的情况下,母鸡能买几只,余下的买小鸡;最后判断时别忘了有三个条件,小鸡数量必须是3的倍数,必须100只鸡,必须花100钱。</p><div class="aritcle_card flexRow artxards">
<div class="artcardd flexRow">
<a class="aritcle_card_img" rel="nofollow" href="/xiazai/skill13095" title="Build Java agent transport gateways with Atmosphere"><img
src="https://img.php.cn/upload/skill/001/246/273/6adaf20e352aa140.jpg" alt="Build Java agent transport gateways with Atmosphere" onerror="this.onerror='';this.src='/static/lhimages/moren/morentu.png'" ></a>
<div class="aritcle_card_info flexColumn">
<a rel="nofollow" href="/xiazai/skill13095" title="Build Java agent transport gateways with Atmosphere" class="overflowclass">Build Java agent transport gateways with Atmosphere</a>
<p class="overflowclass">使用Atmosphere构建通过WebSocket、SSE、gRPC、WebTransport、MCP、A2A和AG-UI流传输的JVM代理网关,并带有治理钩子。</p>
</div>
<a rel="nofollow" href="/xiazai/skill13095" title="Build Java agent transport gateways with Atmosphere" class="aritcle_card_btn flexRow flexcenter"><b></b><span>下载</span>
</a>
</div>
</div><pre class="brush:php;toolbar:false">public class Test4{
public static void main(String [] args){
//声明公鸡数量为变量a;母鸡数量为变量b;小鸡数量为变量c;
int a;
int b;
int c;
for(a=0;a<p>5.输出九九乘法表.</p><p>思路:嵌套循环直接搞定,这里注意第二个数的取值范围要小于等于第一个数</p><pre class="brush:php;toolbar:false">public class Test6{
public static void main(String [] args){
for(int i=1;i<p>6.求水仙花数。<br>所谓水仙花数,是指一个三位数abc,如果满足a的三次方+b的三次方+c的三次方=abc,则abc是水仙花数。</p><p>思路:也不难,只要熟悉数字中的每位数怎么求</p><pre class="brush:php;toolbar:false">public class Test7{
public static void main(String [] args){
for(int n=100;n<p>7.求100以内的质数有哪些?<br>质数:除了1和它本身不能被其它数所整除的数。比如 2,3,5,7,11</p><p>思路:外层循环2-100走一遍,内层循环不确定次数,用while,取余不等于零,则继续下一个数,直到余自身,这个数就是质数</p><pre class="brush:php;toolbar:false">public class Test8 {
public static void main(String[] args) {
int j;
for (int i = 2; i <p>相关文章教程推荐:<a href="https://www.php.cn/java/guide/" target="_blank">java开发入门</a><br></p>
Java免费学习笔记:立即使用
解锁 Java 大师之旅:从入门到精通的终极指南










