for (int i = 1i <= ni++) {
for (int j = 1j <= ij++)
System.out.printf("%d*%d=%d \t", j, i, i * j)
System.out.println()
}
import java.util.*public class T {
public static void main(String[] args){
try{
Scanner input = new Scanner(System.in)
String num = input.nextLine()
if(!num.match("[^0]\\d+$")) {
throw new RuntimeException("输入的不是自然数")
}
if(Long.parseLong(num) >20) {
throw new RuntimeException("数字过大,无法计算")
}
long result = factorial(Long.parseLong(num))
System.out.println(result)
}catch(Exception e){
throw new RuntimeException(e)
}finally{
System.out.println("Finish computing factorial number")
}
}
/**计算阶乘**/
public static long factorial(long n) {
if(n==1) return 1
return n * factorial(n-1)
}
}
import java.util.Randomimport java.util.Scanner
public class Hello {
public static void main(String[] args)
{
Scanner scnner=new Scanner(System.in)
Random random=new Random()
int n=scnner.nextInt()
int a[][]=new int[n][n]
for(int i=0i<n++i)
for(int j=0j<n++j)
{
a[i][j]=random.nextInt(n)//随机产生0~n-1的随机数
}
for(int i=0i<n++i)
{
for(int j=0j<n++j)
{
System.out.print(a[i][j]+" ")
}
System.out.println()
}
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)