LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 01-22-2008, 03:37 PM   #1
rabbit2345
Member
 
Registered: Apr 2007
Location: 中国上海
Distribution: openSUSE 11.3
Posts: 369

Rep: Reputation: 40
package java program into .jar file


hi,

i have written a simple horse race game for my friends and now want to distribute it to some other people. How do i package my program into a .jar file? Do i need to include all the files i imported like java.io.*?

Here is the code
Code:
import java.io.*;
import java.util.*;

public class Horserace10
{
	static Random gen = new Random();

	public static void fx1()
	{
		int horse[] = new int[10];
		int x, y, rand, a, p, d, z;
		String n, pt, h;
		Scanner p1, p2, p1h, p1b, p2h, p2b, hold;
		horse[0] = 0;
		horse[1] = 0;
		horse[2] = 0;
		horse[3] = 0;
		horse[4] = 0;
		horse[5] = 0;
		horse[6] = 0;
		horse[7] = 0;
		horse[8] = 0;
		horse[9] = 0;
		rand = gen.nextInt(300);
		System.out.print("Welcome to the Horse Race Game!" + "\n\n");
		System.out.print("Enter Player 1's name" + "\n\n");
		p1 = new Scanner(System.in);
		n = p1.nextLine();
		System.out.print("\n\nEnter Player 2's name" + "\n\n");
		p2 = new Scanner(System.in);		
		pt = p2.nextLine();
		System.out.print("\nEnter the horse number " + n + " wants to bet on" + " (1 - 10)" + "\n\n#");
		p1h = new Scanner(System.in);
		x = p1h.nextInt();
		System.out.print("\nEnter how much money " + n + " wants to bet on Horse #" + x + "\n\n$");
		p1b = new Scanner(System.in);
		y = p1b.nextInt();
		System.out.print("\nEnter the horse number " + pt + " wants to bet on\n\n#");
		p2h = new Scanner(System.in);
		p = p2h.nextInt();
		System.out.print("\nEnter how much money " + pt + " wants to bet on Horse #" + p + " \n\n$");
		p2b = new Scanner(System.in);
		d = p2b.nextInt();
		System.out.print("\nThe race has started!!, Press enter to continue the race");
		a = rand + y + d;
		z = rand + d + y;
		do
		{
			System.out.print("\n");

			for (int track = 0; track < 10; track++)
			{
				System.out.print("\n\n|");
				for (int i = 0; i < 75; i++)
				{
					if (i != horse[track])
					{
						System.out.print("-");
					}
					else
					{
						System.out.print(track + 1);
					}

				}
				System.out.print("|");
			}
			hold = new Scanner(System.in);
			h = hold.nextLine();
			horse[0] += gen.nextInt(3) + 1;
			horse[1] += gen.nextInt(3) + 1;
			horse[2] += gen.nextInt(3) + 1;
			horse[3] += gen.nextInt(3) + 1;
			horse[4] += gen.nextInt(3) + 1;
			horse[5] += gen.nextInt(3) + 1;
			horse[6] += gen.nextInt(3) + 1;
			horse[7] += gen.nextInt(3) + 1;
			horse[8] += gen.nextInt(3) + 1;
			horse[9] += gen.nextInt(3) + 1;
		}
		while (horse[0] <= 75 && horse[1] <= 75 && horse[2] <= 75 && horse[3] <= 75 && horse[4] <= 75 && horse[5] <= 75 && horse[6] <= 75 && horse[7] <= 75 && horse[8] <= 75 && horse[9] <= 75);

		if (horse[0] > 75 && horse[1] < 75 && horse[2] < 75 && horse[3] < 75 && horse[4] < 75 && horse[5] < 75 && horse[6] < 75 && horse[7] < 75 && horse[8] < 75 && horse[9] < 75)
		{
			System.out.print("			Horse 1 won the race!!");
		}
		if (horse[1] > 75 && horse[0] < 75 && horse[2] < 75 && horse[3] < 75 && horse[4] < 75 && horse[5] < 75 && horse[6] < 75 && horse[7] < 75 && horse[8] < 75 && horse[9] < 75)
		{
			System.out.print("			Horse 2 won the race!!");
		}
		if (horse[2] > 75 && horse[1] < 75 && horse[0] < 75 && horse[3] < 75 && horse[4] < 75 && horse[5] < 75 && horse[6] < 75 && horse[7] < 75 && horse[8] < 75 && horse[9] < 75)
		{
			System.out.print("			Horse 3 won the race!!");
		}
		if (horse[3] > 75 && horse[1] < 75 && horse[2] < 75 && horse[0] < 75 && horse[4] < 75 && horse[5] < 75 && horse[6] < 75 && horse[7] < 75 && horse[8] < 75 && horse[9] < 75)
		{
			System.out.print("			Horse 4 won the race!!");
		}
		if (horse[4] > 75 && horse[1] < 75 && horse[2] < 75 && horse[3] < 75 && horse[0] < 75 && horse[5] < 75 && horse[6] < 75 && horse[7] < 75 && horse[8] < 75 && horse[9] < 75)
		{
			System.out.print("			Horse 5 won the race!!");
		}
		if (horse[5] > 75 && horse[1] < 75 && horse[2] < 75 && horse[3] < 75 && horse[4] < 75 && horse[0] < 75 && horse[6] < 75 && horse[7] < 75 && horse[8] < 75 && horse[9] < 75)
		{
			System.out.print("			Horse 6 won the race!!");
		}
		if (horse[6] > 75 && horse[1] < 75 && horse[2] < 75 && horse[3] < 75 && horse[4] < 75 && horse[5] < 75 && horse[0] < 75 && horse[7] < 75 && horse[8] < 75 && horse[9] < 75)
		{
			System.out.print("			Horse 7 won the race!!");
		}
		if (horse[7] > 75 && horse[1] < 75 && horse[2] < 75 && horse[3] < 75 && horse[4] < 75 && horse[5] < 75 && horse[6] < 75 && horse[0] < 75 && horse[8] < 75 && horse[9] < 75)
		{
			System.out.print("			Horse 8 won the race!!");
		}
		if (horse[8] > 75 && horse[1] < 75 && horse[2] < 75 && horse[3] < 75 && horse[4] < 75 && horse[5] < 75 && horse[6] < 75 && horse[7] < 75 && horse[0] < 75 && horse[9] < 75)
		{
			System.out.print("			Horse 9 won the race!!");
		}
		if (horse[9] > 75 && horse[1] < 75 && horse[2] < 75 && horse[3] < 75 && horse[4] < 75 && horse[5] < 75 && horse[6] < 75 && horse[7] < 75 && horse[8] < 75 && horse[0] < 75)
		{
			System.out.print("			Horse 10 won the race!!");
		}
		if (horse[0] > 75 && horse[1] > 75 && horse[2] < 75 && horse[3] < 75 && horse[4] < 75 && horse[5] < 75 && horse[6] < 75 &&  horse[7] < 75 &&  horse[8] < 75 && horse[9] < 75)
		{
			System.out.print("			Horse 1 and 2 tied!!");
		}
		if (horse[0] > 75 && horse[2] > 75 && horse[1] < 75 && horse[3] < 75 && horse[4] < 75 && horse[5] < 75 && horse[6] < 75 &&  horse[7] < 75 &&  horse[8] < 75 && horse[9] < 75)
		{
			System.out.print("			Horse 1 and 3 tied!!");
		}
		if (horse[0] > 75 && horse[3] > 75 && horse[2] < 75 && horse[1] < 75 && horse[4] < 75 && horse[5] < 75 && horse[6] < 75 &&  horse[7] < 75 &&  horse[8] < 75 && horse[9] < 75)
		{
			System.out.print("			Horse 1 and 4 tied!!");
		}
		if (horse[0] > 75 && horse[4] > 75 && horse[2] < 75 && horse[3] < 75 && horse[1] < 75 && horse[5] < 75 && horse[6] < 75 &&  horse[7] < 75 &&  horse[8] < 75 && horse[9] < 75)
		{
			System.out.print("			Horse 1 and 5 tied!!");
		}
		if (horse[0] > 75 && horse[5] > 75 && horse[2] < 75 && horse[3] < 75 && horse[4] < 75 && horse[1] < 75 && horse[6] < 75 &&  horse[7] < 75 &&  horse[8] < 75 && horse[9] < 75)
		{
			System.out.print("			Horse 1 and 6 tied!!");
		}
		if (horse[0] > 75 && horse[6] > 75 && horse[2] < 75 && horse[3] < 75 && horse[4] < 75 && horse[5] < 75 && horse[1] < 75 &&  horse[7] < 75 &&  horse[8] < 75 && horse[9] < 75)
		{
			System.out.print("			Horse 1 and 7 tied!!");
		}
		if (horse[0] > 75 && horse[7] > 75 && horse[2] < 75 && horse[3] < 75 && horse[4] < 75 && horse[5] < 75 && horse[6] < 75 &&  horse[1] < 75 &&  horse[8] < 75 && horse[9] < 75)
		{
			System.out.print("			Horse 1 and 8 tied!!");
		}
		if (horse[0] > 75 && horse[8] > 75 && horse[2] < 75 && horse[3] < 75 && horse[4] < 75 && horse[5] < 75 && horse[6] < 75 &&  horse[7] < 75 &&  horse[1] < 75 && horse[9] < 75)
		{
			System.out.print("			Horse 1 and 9 tied!!");
		}
		if (horse[0] > 75 && horse[9] > 75 && horse[2] < 75 && horse[3] < 75 && horse[4] < 75 && horse[5] < 75 && horse[6] < 75 &&  horse[7] < 75 &&  horse[8] < 75 && horse[1] < 75)
		{
			System.out.print("			Horse 1 and 10 tied!!");
		}
		if (horse[1] > 75 && horse[2] > 75 && horse[0] < 75 && horse[3] < 75 && horse[4] < 75 && horse[5] < 75 && horse[6] < 75 &&  horse[7] < 75 &&  horse[8] < 75 && horse[9] < 75)
		{
			System.out.print("			Horse 2 and 3 tied!!");
		}
		if (horse[1] > 75 && horse[3] > 75 && horse[2] < 75 && horse[0] < 75 && horse[4] < 75 && horse[5] < 75 && horse[6] < 75 &&  horse[7] < 75 &&  horse[8] < 75 && horse[9] < 75)
		{
			System.out.print("			Horse 2 and 4 tied!!");
		}
		if (horse[1] > 75 && horse[4] > 75 && horse[2] < 75 && horse[3] < 75 && horse[0] < 75 && horse[5] < 75 && horse[6] < 75 &&  horse[7] < 75 &&  horse[8] < 75 && horse[9] < 75)
		{
			System.out.print("			Horse 2 and 5 tied!!");
		}
		if (horse[1] > 75 && horse[5] > 75 && horse[2] < 75 && horse[3] < 75 && horse[4] < 75 && horse[0] < 75 && horse[6] < 75 &&  horse[7] < 75 &&  horse[8] < 75 && horse[9] < 75)
		{
			System.out.print("			Horse 2 and 6 tied!!");
		}
		if (horse[1] > 75 && horse[6] > 75 && horse[2] < 75 && horse[3] < 75 && horse[4] < 75 && horse[5] < 75 && horse[0] < 75 &&  horse[7] < 75 &&  horse[8] < 75 && horse[9] < 75)
		{
			System.out.print("			Horse 2 and 7 tied!!");
		}
		if (horse[1] > 75 && horse[7] > 75 && horse[2] < 75 && horse[3] < 75 && horse[4] < 75 && horse[5] < 75 && horse[6] < 75 &&  horse[0] < 75 &&  horse[8] < 75 && horse[9] < 75)
		{
			System.out.print("			Horse 2 and 8 tied!!");
		}
		if (horse[1] > 75 && horse[8] > 75 && horse[2] < 75 && horse[3] < 75 && horse[4] < 75 && horse[5] < 75 && horse[6] < 75 &&  horse[7] < 75 &&  horse[0] < 75 && horse[9] < 75)
		{
			System.out.print("			Horse 2 and 9 tied!!");
		}
		if (horse[1] > 75 && horse[9] > 75 && horse[2] < 75 && horse[3] < 75 && horse[4] < 75 && horse[5] < 75 && horse[6] < 75 &&  horse[7] < 75 &&  horse[8] < 75 && horse[0] < 75)
		{
			System.out.print("			Horse 2 and 10 tied!!");
		}
		if (horse[2] > 75 && horse[3] > 75 && horse[1] < 75 && horse[0] < 75 && horse[4] < 75 && horse[5] < 75 && horse[6] < 75 &&  horse[7] < 75 &&  horse[8] < 75 && horse[9] < 75)
		{
			System.out.print("			Horse 3 and 4 tied!!");
		}
		if (horse[2] > 75 && horse[4] > 75 && horse[1] < 75 && horse[3] < 75 && horse[0] < 75 && horse[5] < 75 && horse[6] < 75 &&  horse[7] < 75 &&  horse[8] < 75 && horse[9] < 75)
		{
			System.out.print("			Horse 3 and 5 tied!!");
		}
		if (horse[2] > 75 && horse[5] > 75 && horse[1] < 75 && horse[3] < 75 && horse[4] < 75 && horse[0] < 75 && horse[6] < 75 &&  horse[7] < 75 &&  horse[8] < 75 && horse[9] < 75)
		{
			System.out.print("			Horse 3 and 6 tied!!");
		}
		if (horse[2] > 75 && horse[6] > 75 && horse[1] < 75 && horse[3] < 75 && horse[4] < 75 && horse[5] < 75 && horse[0] < 75 &&  horse[7] < 75 &&  horse[8] < 75 && horse[9] < 75)
		{
			System.out.print("			Horse 3 and 7 tied!!");
		}
		if (horse[2] > 75 && horse[7] > 75 && horse[1] < 75 && horse[3] < 75 && horse[4] < 75 && horse[5] < 75 && horse[6] < 75 &&  horse[0] < 75 &&  horse[8] < 75 && horse[9] < 75)
		{
			System.out.print("			Horse 3 and 8 tied!!");
		}
		if (horse[2] > 75 && horse[8] > 75 && horse[1] < 75 && horse[3] < 75 && horse[4] < 75 && horse[5] < 75 && horse[6] < 75 &&  horse[7] < 75 &&  horse[0] < 75 && horse[9] < 75)
		{
			System.out.print("			Horse 3 and 9 tied!!");
		}
		if (horse[2] > 75 && horse[9] > 75 && horse[1] < 75 && horse[3] < 75 && horse[4] < 75 && horse[5] < 75 && horse[6] < 75 &&  horse[7] < 75 &&  horse[8] < 75 && horse[0] < 75)
		{
			System.out.print("			Horse 3 and 10 tied!!");
		}
		if (horse[3] > 75 && horse[4] > 75 && horse[2] < 75 && horse[1] < 75 && horse[0] < 75 && horse[5] < 75 && horse[6] < 75 &&  horse[7] < 75 &&  horse[8] < 75 && horse[9] < 75)
		{
			System.out.print("			Horse 4 and 5 tied!!");
		}
		if (horse[3] > 75 && horse[5] > 75 && horse[2] < 75 && horse[1] < 75 && horse[4] < 75 && horse[0] < 75 && horse[6] < 75 &&  horse[7] < 75 &&  horse[8] < 75 && horse[9] < 75)
		{
			System.out.print("			Horse 4 and 6 tied!!");
		}
		if (horse[3] > 75 && horse[6] > 75 && horse[2] < 75 && horse[1] < 75 && horse[4] < 75 && horse[5] < 75 && horse[0] < 75 &&  horse[7] < 75 &&  horse[8] < 75 && horse[9] < 75)
		{
			System.out.print("			Horse 4 and 7 tied!!");
		}
		if (horse[3] > 75 && horse[7] > 75 && horse[2] < 75 && horse[1] < 75 && horse[4] < 75 && horse[5] < 75 && horse[0] < 75 &&  horse[6] < 75 &&  horse[8] < 75 && horse[9] < 75)
		{
			System.out.print("			Horse 4 and 8 tied!!");
		}
		if (horse[3] > 75 && horse[8] > 75 && horse[2] < 75 && horse[1] < 75 && horse[4] < 75 && horse[5] < 75 && horse[0] < 75 &&  horse[7] < 75 &&  horse[6] < 75 && horse[9] < 75)
		{
			System.out.print("			Horse 4 and 9 tied!!");
		}
		if (horse[3] > 75 && horse[9] > 75 && horse[2] < 75 && horse[1] < 75 && horse[4] < 75 && horse[5] < 75 && horse[6] < 75 &&  horse[7] < 75 &&  horse[8] < 75 && horse[0] < 75)
		{
			System.out.print("			Horse 4 and 10 tied!!");
		}
		if (horse[4] > 75 && horse[5] > 75 && horse[0] < 75 && horse[1] < 75 && horse[2] < 75 && horse[3] < 75 && horse[6] < 75 &&  horse[7] < 75 &&  horse[8] < 75 && horse[9] < 75)
		{
			System.out.print("			Horse 5 and 6 tied!!");
		}
		if (horse[4] > 75 && horse[6] > 75 && horse[5] < 75 && horse[1] < 75 && horse[2] < 75 && horse[3] < 75 && horse[0] < 75 &&  horse[7] < 75 &&  horse[8] < 75 && horse[9] < 75)
		{
			System.out.print("			Horse 5 and 7 tied!!");
		}
		if (horse[4] > 75 && horse[7] > 75 && horse[0] < 75 && horse[1] < 75 && horse[2] < 75 && horse[3] < 75 && horse[6] < 75 &&  horse[5] < 75 &&  horse[8] < 75 && horse[9] < 75)
		{
			System.out.print("			Horse 5 and 8 tied!!");
		}
		if (horse[4] > 75 && horse[8] > 75 && horse[0] < 75 && horse[1] < 75 && horse[2] < 75 && horse[3] < 75 && horse[6] < 75 &&  horse[7] < 75 &&  horse[5] < 75 && horse[9] < 75)
		{
			System.out.print("			Horse 5 and 9 tied!!");
		}
		if (horse[4] > 75 && horse[9] > 75 && horse[0] < 75 && horse[1] < 75 && horse[2] < 75 && horse[3] < 75 && horse[6] < 75 &&  horse[7] < 75 &&  horse[8] < 75 && horse[5] < 75)
		{
			System.out.print("			Horse 5 and 10 tied!!");
		}
		if (horse[5] > 75 && horse[6] > 75 && horse[0] < 75 && horse[1] < 75 && horse[2] < 75 && horse[3] < 75 && horse[4] < 75 &&  horse[7] < 75 &&  horse[8] < 75 && horse[9] < 75)
		{
			System.out.print("			Horse 6 and 7 tied!!");
		}
		if (horse[5] > 75 && horse[7] > 75 && horse[0] < 75 && horse[1] < 75 && horse[2] < 75 && horse[3] < 75 && horse[4] < 75 &&  horse[6] < 75 &&  horse[8] < 75 && horse[9] < 75)
		{
			System.out.print("			Horse 6 and 8 tied!!");
		}
		if (horse[5] > 75 && horse[8] > 75 && horse[0] < 75 && horse[1] < 75 && horse[2] < 75 && horse[3] < 75 && horse[4] < 75 &&  horse[7] < 75 &&  horse[6] < 75 && horse[9] < 75)
		{
			System.out.print("			Horse 6 and 9 tied!!");
		}
		if (horse[5] > 75 && horse[9] > 75 && horse[0] < 75 && horse[1] < 75 && horse[2] < 75 && horse[3] < 75 && horse[4] < 75 &&  horse[7] < 75 &&  horse[8] < 75 && horse[6] < 75)
		{
			System.out.print("			Horse 6 and 10 tied!!");
		}
		if (horse[7] > 75 && horse[8] > 75 && horse[0] < 75 && horse[1] < 75 && horse[2] < 75 && horse[3] < 75 && horse[4] < 75 &&  horse[5] < 75 &&  horse[6] < 75 && horse[9] < 75)
		{
			System.out.print("			Horse 8 and 9 tied!!");
		}
		if (horse[7] > 75 && horse[9] > 75 && horse[0] < 75 && horse[1] < 75 && horse[2] < 75 && horse[3] < 75 && horse[4] < 75 &&  horse[5] < 75 &&  horse[6] < 75 && horse[8] < 75)
		{
			System.out.print("			Horse 8 and 10 tied!!");
		}
		if (horse[8] > 75 && horse[9] > 75 && horse[0] < 75 && horse[1] < 75 && horse[2] < 75 && horse[3] < 75 && horse[4] < 75 &&  horse[5] < 75 &&  horse[6] < 75 && horse[7] < 75)
		{
			System.out.print("			Horse 9 and 10 tied!!");
		}
		if (horse[0] > 75 && x == 1 || horse[1] > 75 && x == 2 || horse[2] > 75 && x == 3 || horse[3] > 75 && x == 4 || horse[4] > 75 && x == 5 || horse[5] > 75 && x == 6 || horse[6] > 75 && x == 7 || horse[7] > 75 && x == 8 || horse[8] > 75 && x == 9 || horse[9] > 75 && x == 10)
		{
			a += y;
			System.out.print("\n\n		" + n + " has bet on the right horse! " + n + " won $" + a + "!!");
		}

		if (horse[0] < 75 && x == 1 || horse[1] < 75 && x == 2 || horse[2] < 75 && x == 3 || horse[3] < 75 && x == 4 || horse[4] < 75 && x == 5  || horse[5] < 75 && x == 6 || horse[6] < 75 && x == 7  || horse[7] < 75 && x == 8  || horse[8] < 75 && x == 9  || horse[9] < 75 && x == 10)
		{
			a -= y;
			System.out.print("\n\n		" + n + " has bet on the wrong horse! " + n + " lost $" + y + "!!");
		}
		if (x > 10 || x < 1)
		{
			System.out.print("\n\n		" + n + " bet on a non-exsisting horse, so " + n + " lost $" + y + "!!");
		}
		if (horse[0] > 75 && p == 1 || horse[1] > 75 && p == 2 || horse[2] > 75 && p == 3 || horse[3] > 75 && p == 4 || horse[4] > 75 && p == 5 || horse[5] > 75 && p == 6 || horse[6] > 75 && p == 7 || horse[7] > 75 && p == 8 || horse[8] > 75 && p == 9 || horse[9] > 75 && p == 10)
		{
			a += d;
			System.out.print("\n\n		" + pt + " has bet on the right horse! " + pt + " won $" + z + "!!");
		}
		if (horse[0] < 75 && p == 1 || horse[1] < 75 && p == 2 || horse[2] < 75 && p == 3 || horse[3] < 75 && p == 4 || horse[4] < 75 && p == 5 || horse[5] < 75 && p == 6 || horse[6] < 75 && p == 7 || horse[7] < 75 && p == 8 || horse[8] < 75 && p == 9 || horse[9] < 75 && p == 10)
		{
			a -= d;
			System.out.print("\n\n		" + pt + " has bet on the wrong horse! " + pt + " lost $" + d + "!!");
		}
		if (p > 10)
		{
			System.out.print("\n\n		" + pt + " bet on a non-exsisting horse, so " + pt + " lost $" + d + "!!");
		}
	}
	public static void main(String[] args)
    {
for (int lo = 0; lo < 10; lo++)
	{
	int ch;
	Scanner choice;		
	fx1();
	System.out.print("\n\n	Nice Race!! If you want to play again, type 1 or type 2 to exit\n:");
	choice = new Scanner(System.in);
	ch = choice.nextInt();
		if (ch == 1)
		{ 
		System.out.print("\n\nHorse Race 10 is restarting...Done\n\n\n");
		lo = 2;
		}
		if (ch == 2)
		{
		System.out.print("\n\nHorse Race 10 is exiting... :(\n\n\nThanks for playing Horse Race 10!\n\n");
		lo = 15;
		}
	}
    }
}
also, is there another way to make the program handle ties without writing out all the different combinations?


thanks,
rabbit2345
 
Old 01-22-2008, 03:46 PM   #2
indienick
Senior Member
 
Registered: Dec 2005
Location: London, ON, Canada
Distribution: Arch, Ubuntu, Slackware, OpenBSD, FreeBSD
Posts: 1,853

Rep: Reputation: 65
Read the manpage for jar, or java, and there should be a description on how to do it.

Instead of doing each comparison by hand, why not use a general comparison template with two, nested FOR loops?
 
Old 01-22-2008, 04:04 PM   #3
rabbit2345
Member
 
Registered: Apr 2007
Location: 中国上海
Distribution: openSUSE 11.3
Posts: 369

Original Poster
Rep: Reputation: 40
i'm not sure what you mean by a comparison template with 2 for loops, could you post a small example of that?

thanks
 
Old 01-22-2008, 04:08 PM   #4
jay73
Guru
 
Registered: Nov 2006
Location: Belgium
Distribution: Ubuntu 11.04, Debian testing
Posts: 5,019

Rep: Reputation: 130Reputation: 130
That sure is a lot of code.
For starters, you don't need to assign 0 to each element in your array since an array of ints will have 0s by default.

You can also reduce the last part by using loops or using Arrays methods binarySearch() and sort() and using Math method max().

Last edited by jay73; 01-22-2008 at 04:09 PM.
 
Old 01-23-2008, 07:41 AM   #5
indienick
Senior Member
 
Registered: Dec 2005
Location: London, ON, Canada
Distribution: Arch, Ubuntu, Slackware, OpenBSD, FreeBSD
Posts: 1,853

Rep: Reputation: 65
Quote:
Originally Posted by rabbit2345
i'm not sure what you mean by a comparison template with 2 for loops, could you post a small example of that?
What I simply mean is:
Code:
for (int x = 0; x < 10; x++) {

  if (horse[x] > 75)

    for (int y = (x + 1); y < 10; y++) {

      // a quick, sorting algorithm to figure out
      // which horse came first...

    }

}
What I meant was to use two FOR loops to iterate through the array.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to run JAR from within Java program ?! EAD Programming 1 12-31-2006 07:11 PM
Where do I install a Java .jar file? cumbersome Slackware 1 04-22-2006 01:46 PM
Package .jar file for BalancerFilter class minil Programming 0 12-20-2005 04:20 AM
How to run a java jar file. sabliny Programming 7 11-05-2005 01:59 PM
How jar java program? treotan Programming 3 09-08-2005 12:03 AM


All times are GMT -5. The time now is 03:13 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration