I am new to the Java language and have a class that deals with the basics of the language as well as one dealing with the OOP of it all. I am stuck trying to figure out how to finish a program that creates a palindrome from an array. Basically I need to conform to these:

- makePalindrome: takes a single parameter, an array of integers, each containing a single digit of the odometer. This function should modify the numbers in the higher-numbered positions of the array so that the odometer forms a palindrome. For example, given the the array {1, 0, 2, 4, 1, 7} as input, the function should rewrite this to {1, 0, 2, 2, 0, 1}.

- getValue: takes a single input parameter, an array of integers, each containing a single digit of the odometer. As output returns a long integer containing the equivalent value of that odometer. For example, given the the array {1, 0, 2, 4, 1, 7} as input, the function should return 102417.

- addOne: takes two parameters. The first is an array of integers, each containing a single digit of the odometer. The second parameter should be an integer, denoting a position within the array. The function should add one to the element in the indicated position. If that element should then exceed 9, then 10 is subtracted from that element, andthe process repeated for the element in the next lower position (unless we are already in position 0).

For example, given the input array {9, 9, 0, 4, 1} and a position number of 4, the array should be rewritten as {9, 9, 0, 4, 2}. But given that same input array and a position number of 1, the array would be rewritten as {0, 0, 0, 4, 1}.

Input & Interaction

Input to the program will be taken from the standard input ( System.in).

There will be several test cases in the input, each consisting of an odometer reading on its own line. Each odometer reading will be from 2 to 9 digits long. The odometer in question has the number of digits given in the input - so, if the input is 00456, the odometer has 5 digits. There will be no spaces in the input, and no blank lines between input sets.

The input will end with a line with a single 0.

Here is what I have tried:

import java.io.*; import java.util.*; public class Odometer { public Scanner sc; public PrintStream ps; public void makePalindrome (int[] s) { // your code here try { sc = new Scanner(System.in); while (sc.hasNextInt()) //Loop through while there are ints and load them into a temp array { int [] temp; int i = sc.nextInt(); temp = new int[i]; } } sc.close(); } public long getValue(int[] s) { // your code here // System.out(array[i]); after I have made the palindrome } public void addOne (int[] digits, int pos) { // your code here //Something like? int[] temp; temp.sort(digits); temp.binarysearch(digits, pos); temp [] + 1; } public int[] parseInput (String s) { int[] digits = new int[s.length()]; for (int i = 0; i < digits.length; ++i) digits[i] = s.charAt(i) - '0'; return digits; } /** * Driver. * @throws Exception */ public void execute(BufferedReader input) { try { while (true) { String reading = input.readLine(); if (reading.equals("0")) break; int[] digits = parseInput(reading); long startingValue = getValue (digits); makePalindrome (digits); long target = getValue (digits); if (target < startingValue) { addOne (digits, (digits.length + 1) / 2 - 1); makePalindrome (digits); target = getValue (digits); } System.out.println(reading + " " + (target - startingValue) ); } } catch (IOException e) { // Thrown on illegal input or end of input } } /** * The main just creates an object and calls doit(). * * @param args Command line args, necessary but unused. * @throws FileNotFoundException */ public static void main( String[] args ) throws FileNotFoundException { BufferedReader input = null; if (args.length == 0) { input = new BufferedReader(new InputStreamReader(System.in)); } else { input = new BufferedReader (new FileReader (args[0])); } new Odometer().execute(input); } }

Thanks in advance for any help.