- #1

Tickitata

- 29

- 0

Code:

```
import java.util.*;
public class ZnX
{
public static int gcd(int a, int b)
{
if (b==0)
return a;
else
return gcd(b, a % b);
}
public static void main(String[] args)
{
final int TWO_DIGITS = 10;
int n = 0;
int[] primes = new int[0];
System.out.println("Multiplication table for Z modulo n");
System.out.println("Please enter n: ");
Scanner scan = new Scanner(System.in);
// Calculating Relatively Prime Integers
while(scan.hasNextInt())
{
if(scan.hasNextInt())
{
n = scan.nextInt();
primes = new int[n];
// System.out.print("The set of relatively prime integers to " + n + " is: {");
}
else
{
System.out.println("Input is not an integer, terminating program");
System.exit(0);
}
int j = 0;
for(int i = 0; i <= n; i++)
{
if(gcd(i,n) == 1)
{
primes[j] = i;
// System.out.print(i + ", ");
j++;
}
}
// System.out.println("}");
// System.out.println("Number of elements: " + j);
System.out.println("The multiplication table for Z modulo " + n + " is:");
int[][] multTable = new int[j][j];
for(int row = 0; row < j; row++)
{
for(int col = 0; col < j; col++)
{
multTable[row][col] = (primes[row] * primes[col]) % n;
System.out.print(multTable[row][col]);
if((multTable[row][col]) < TWO_DIGITS)
System.out.print(" ");
else
System.out.print(" ");
}
System.out.print("\n");
} // End for loop
System.out.println("\nPlease enter another integer: ");
} // End while loop
System.out.println("End of valid integers, terminating program");
} // End main
} // End class
```

This code compiles and runs correctly from the commandline. Now, because I'm writing this for my computer illiterate math teacher, I'd like to create an executable file (.jar?) which she can simply double click to run

Is there any way to do this without using GUI/applets?

Thanks!