⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sum.txt

📁 编写如下方法:求一个长整数的各位数之和:public static int qiuhe(long s) 找10~100之间能被3或5整除的数
💻 TXT
字号:
1.编写如下方法:
	求一个长整数的各位数之和:public static int qiuhe(long s)
 class t1
 {public static int qiuhe(long s)
  {int sum=0;
   while(s>0)
    {sum=sum+(int)s%10;
     s=s/10;
    }
  return sum;
 }
   public static void main(String [] args)
	{long a=3695l;		
	 System.out.println("该整数的每个位数相加和为:"+qiuhe(a));
	}
  }
2.找10~100之间能被3或5整除的数,每行输出5个数。
class  t2
{
	public static void main(String args[])
	{
		int j=0;
		for(int i=10;i<=100;i++)
		{
			if(i%3==0||i%5==0)
			{
				System.out.print(i+" ");
				j++;
			if(j==5)
			{
				j=0;
				System.out.println();
			}
			}
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -