1. 设计一个方法, 取名叫getCount用来计算出1-100之间有多少能被3整除,要求有返回值,并把结果打印在控制台上.
class Demo
{
public static void main(string[] args)
{
gettcount() ;
}
public static void getcount()
{
int sum=0;
for (int x=1;x<=100;x++)
{
if (x%3==0)
sum++;
}
System.out.println(“s um=”+sum);
}
2. 设计一个方法,用来打印出下面的图形,取名为printJuXing. 把图形打印在控制台上,不要返回值.
*****
*****
*****
*****
class Demo
{
public static void mian(string[] args)
{
printJuXing(4,5);
}
public static void printJuXing(int a,int b)
for (int x=0;x<a;x++)
{
for (int y=0;y<b;y++)
{
System.out.prin(“*”);
}
System.out.println();
}
}
printJuXing(4,5);
}
public static void printJuXing(int a,int b)
for (int x=0;x<a;x++)
{
for (int y=0;y<b;y++)
{
System.out.prin(“*”);
}
System.out.println();
}
}
|
|