/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package javaapplication2; /** * * @author zzaier */ public class JavaApplication2 { /** * @param args the command line arguments */ public static void main(String[] args) { int[] anArray = {1, 3, 3, 5, 7, 7, 8, 9}; //int resultOfA =A(5); duplicate(anArray); //System.out.println("result Of A " + resultOfA); printZied(); double myDivision = printDivision(5, 2); System.out.println(" result division " + myDivision); System.out.println("////////////////////"); char[] toCheck1 = {'K', 'A', 'Y', 'A', 'K'}; boolean isPalendrome = palindrome(toCheck1); System.out.println("KAYAK is a PALINDROME " + isPalendrome); System.out.println("////////////////////"); char[] toCheck2 = {'A', 'B', 'C', 'D', 'E', 'F', 'F', 'G', 'D', 'C', 'B', 'A'}; isPalendrome = palindrome(toCheck2); System.out.println("ABCDEFFGDCBA is a PALINDROME " + isPalendrome); int[] anArray1 = {1, 3, 37, 5, 7, 77, 8, 99}; int[] resultArray = insert(anArray1, 4, 2); for (int i = 0; i < resultArray.length; i++) { System.out.print(resultArray[i] + " "); } } static public int[] insert(int[] myArray, int value, int position) { for (int i = myArray.length - 2; i >= position; i--) { myArray[i + 1] = myArray[i]; } myArray[position] = value; return myArray; } static public boolean palindrome(char[] myArray) { int i = 0; while (i < (myArray.length / 2) && myArray[i] == myArray[myArray.length - i - 1]) { i++; } if (i < myArray.length / 2) { return false; } else { return true; } } static public void duplicate(int[] myArray) { for (int i = 0; i < myArray.length - 1; i++) { if (myArray[i] == myArray[i + 1]) { System.out.println(myArray[i]); } } } static public void printZied() { System.out.println("Zied "); } static public double printDivision(int value1, int value2) { double result = (double) value1 / (double) value2; return result; } }