All pastes #946832 Raw Edit

blab

public java v1 · immutable
·published 2008-03-17 23:38 UTC
rendered paste body
public class Array_Third {	public static void main(String arg[])	{		// Integer Array of numbers.		/*int num[] = {5, 6, 77, 34, 24, 61, 36, 40, 88, 69, 47, 34, 68, 1,					13, 21, 75, 42, 13, 46, 5, 48, 59, 39, 5, 83, 55, 97,					3, 40, 70, 24, 15, 3, 31, 39, 17, 6, 45, 1, 94, 31, 53,					29, 74, 82, 77, 44, 44, 18, 23 };*/		// Using the numbers from the PDF temporarily so we can check against		// the correct result given by the professor		int num[] = { 1, 2, 100, 4, 3, 100, 5, 4, 100, 1, 9, 100 };				// Loop through num[], starting at num[2] (which is the first "third"). On		// each iteration, instead of "i++", we do "i+=3", which adds three to i instead		// of one, thus jumps us forward to the next third automagically		for (int i=2; i<num.length; i+=3) {			// Test according to what the PDF says to do, nice and simple			// Note that I don't use brackets around the if, else etc. because			// they are followed by only one statement each. More than one statement			// requires brackets surrounding the multiple lines			if (num[i-2] < num[i-1])				num[i] = 1;			else				num[i] = 0;		}				// Print out the new num[], along with a newline for neatness		for (int i=0; i<num.length; i++)			System.out.print(num[i] + (i == num.length-1 ? "" : ", "));		System.out.println();	}}