1 Write a method to print a 99 multiplication table with a for loop/**
* One for loop print 99 multiplication table
*/
public void nineninemultitable ()
{
for (int i = 1,J = 1; J <= 9; i++) {
System.out.print (i+ "*" +j+ "=" +i*j+ "");
if (I==J)
{
i=0;
j + +;
System.out.println ();
}
}
}
2. Write a method that can infer whether an integer is prime (prime number except 1 times its own no other can get this value)/**
* Infer whether an integer is a prime number
* @paramn
* @returnboolean
*/
public boolean isprimes (int n)
{
for (int i = 2; I <= math.sqrt (n); i++) {
if (n%i==0)
{
return false;
}
}
return true;
}
3. Write a method, enter a random integer, and return its factorial (for example, 3 is 1*2*3=6)/**
* Get the factorial of a random integer
* @paramn
* @returnn!
*/
publicint factorial (int n)
{
Recursive
if (n==1)
{
return 1;
}
Return n*factorial (n-1);
Non-recursive
int multi = 1;
for (int i = 2; I <= n; i++) {
Multi*=i;
// }
return multi;
}
Java Foundation Instance (i)