Please help me with the following java program I urgently ne
Please help me with the following java program. I urgently need help with this and have not been able to find any useful help yet. Please do not use random google codes. Thank you.
The requierments are:
Create an array of 52 numbers in the following format: {1,1,1,1,2,2,2,2,3,3,3,3,...........13,13,13,13}
Then iterate through this array and pick four random numbers. Next, use stacks to evaluate an expression (\"+\" , \"-\", \" / \" , or \" * \" ) in postfix notation.
This program is to then find what 4-number combination (using the four random numbers) will evaluate to equal 24 using the expressions in postfix notation from the previous step. This program will then print out one of the solutions for the combination and then continue on to the next random set of numbers.
Solution
import java.util.ArrayList;
import java.util.Collections;
public class UniqueRandomNumbers {
public static void main(String[] args) {
int[] intArray = new int[] {1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,6,6,6,6,7,7,7,7,8,8,8,8,9,9,9,9,10,10,10,10,11,11,11,11,12,12,12,12,13,13,13,13};
System.out.println(intArray);
ArrayList<Integer> list = new ArrayList<Integer>();
for (int i=1; i<52; i++) {
list.add(new Integer(i));
}
Collections.shuffle(list);
for (int i=0; i<4; i++) {
System.out.println(list.get(i));
}
public static int evalPostfix(String exp) {
int res = 0;
myStack list = new myStack();
int n1; //result of 1st popping
int n2; // result of 2nd popping
for (int i = 0; i < exp.length(); i++) {
char ch = exp.charAt(i);
if (ch == \' \') {
} else {
if (ch > \'0\' && ch < \'9\') {
list.push(ch);
// list.printS();
} else {
n1 = Integer.parseInt(\"\" + list.pop());
n2 = Integer.parseInt(\"\" + list.pop());
switch (ch) {
case \'+\':
list.push(n1 + n2);
break;
case \'-\':
list.push(n1 - n2);
break;
case \'*\':
list.push(n1 * n2);
break;
case \'/\':
list.push(n1 / n2);
break;
default:
System.out.println(\"Invalid operator order!\");
}
}
}
}
res = Integer.parseInt(\"\" + list.pop());
return res;
}

