source file name: mathdemo4.java
class mathdemo4
{
public static void main(String as[])
{
System.out.println("squares and cubes of any 10 random numbers: ");
System.out.println("n\tsquare\tcube");
for(int b=1;b<=10;b++)
{
int n=(int)(20*Math.random());
int sq=n*n;
int cube=n*n*n;
System.out.println(n+"\t"+sq+"\t"+cube);
}
}
}
output:
D:\JavaPrograms\Misc>javac mathdemo4.java
D:\JavaPrograms\Misc>java mathdemo4
squares and cubes of any 10 random numbers:
n square cube
8 64 512
11 121 1331
12 144 1728
15 225 3375
19 361 6859
11 121 1331
12 144 1728
10 100 1000
9 81 729
16 256 4096
0 Comments
Post a Comment