public class PracticeTest2015
{
	public static void main(String [] args)
	{
		PracticeTest2015 run = new PracticeTest2015();
		new PracticeTest2015();
		run.methods();
	}
	
	public void methods ( )
	{
		System.out.println("\n\n");
		methodOne();
		System.out.println("\n\n");
		methodTwo();
		System.out.println("\n\n");
		methodThree();
		System.out.println("\n\n");
		System.out.println(alternate("pot","cab"));
		System.out.println(alternate("mixed","up"));
		System.out.println(alternate("excellent","work"));
		System.out.println(alternate("long","weekend"));
		System.out.println("\n\n");
		int [] array = {10, 20, 30, 40, 50, 60};    
		System.out.println(positionOfClosest(array, 47));
		System.out.println(positionOfClosest(array, 23));
		System.out.println(positionOfClosest(array, 83));
		System.out.println(positionOfClosest(array, 1));
		System.out.println("\n\n");
		printArray(countVowels("aardvark"));
		printArray(countVowels("programming"));
		printArray(countVowels("EXCELLENT!"));
		printArray(countVowels("COOL METHOD"));
		System.out.println("\n\n");
	}
	
	public void methodOne ( )
	{		
		int x = 2;
		int number = 3;
		int value = 10;

		while (value < 18)
		{
			if (value % number  == 0)
			{
				value++;
				number++;
			}
			else if (value % x == 0)
			{
				value++;
				x++;
			}
			else
			{
				number--;
				x--;
			}
			value++;
			System.out.println(x + "   " + number + "   " + value);
		}
	}
	
	public void methodTwo ( )
	{
		for (int row = 1; row <= 5; row++)
		{
			int column = 1;
			while (column <= 5)
			{
				if (row == column || row + column == 5)
					System.out.print(row);
				else
					System.out.print("*");      //  an asterisk
				column++;
			} 
			System.out.println();              		  //  a new line
		}
	}
	
	public void methodThree ( )
	{
		System.out.println("\n" + ((int) (Math.PI * 100) == 314));
		System.out.println("" + (89 / 23 + 67 - 16 % 17 * 4));
//		System.out.println("" + ((! 65 > 4 * 15 || false)));
		System.out.println("" + (! (8 / 7.8 > 1 && true) || (int) 7.4 < 7.4));
		System.out.println("" + (65 * 10.0 > 1324 / 4 && 30 / 9 < 3.0 || ! true));
		System.out.println();
	}

	public String alternate (String one, String two)
	{
		String result = new String("");
		for(int i = 0; i < one.length() || i < two.length(); i++)
		{
			if(i < one.length())
			{
				result += one.charAt(i);
			}
			if(i < two.length())
			{
				result += two.charAt(i);
			}
		}
		return result;
	}

	public int positionOfClosest  (int [] a, int value)
	{
		int index = 0, dist = Math.abs(value - a[0]);
		for(int i = 1; i < a.length; i++)
		{
			if(Math.abs(value - a[i]) < dist)
			{
				index = i;
				dist = Math.abs(value - a[i]);
			}
		}
		return index;
	}

	public int [] countVowels(String str)
	{
		str = str.toUpperCase();
		int [] vowelCount = new int[5];
		for(int i = 0; i < str.length(); i++)
		{
			switch(str.charAt(i))
			{
				case 'A':	vowelCount[0]++;	break;
				case 'E':	vowelCount[1]++;	break;
				case 'I':	vowelCount[2]++;	break;
				case 'O':	vowelCount[3]++;	break;
				case 'U':	vowelCount[4]++;	break;
			}
		}
		return vowelCount;
	}
	
	public void printArray(int [] a)
	{
		for(int i = 0; i < a.length; i++)
		{
			System.out.print(a[i] + "  ");
		}
		System.out.println();
	}
}

Back to APCS Main Page