Java programming help please. Thank you so so much. i have to Write a program that does the following: You have an array of integers with positive and negative values. using 1 "ourArray" object (will post code of "ourArrary" below), and in two loops maximum, How can you reorganize the content of the array so that all negative numbers are on one side and the positive numbers are on the other side. [-3, 2, -4, 5, -6, -8,-9, 7, 13] The output should be [-3, -4, -6, -8, -9, 2, 5, 7, 13]
Java
i have to Write a program that does the following:
You have an array of integers with positive and negative values. using 1 "ourArray" object (will post code of "ourArrary" below), and in two loops maximum, How can you reorganize the content of the array so that all negative numbers are on one side and the positive numbers are on the other side.
[-3, 2, -4, 5, -6, -8,-9, 7, 13] The output should be [-3, -4, -6, -8, -9, 2, 5, 7, 13]
MAIN class:
public class Tester {
public static void main(String[] args) {
//create an object ourArray
ourArray<Integer> A = new ourArray<Integer>(5);
//add elements to the back
A.addBack(-3);
A.addBack(-7);
A.addBack(-9);
System.out.println("A: " + A.toString());
A.addFront(-11);
A.addFront(-13);
System.out.println("A: " + A.toString());
System.out.println("removing the back: " + A.removeBack());
System.out.println("A: " + A.toString());
System.out.println("removing the front: " + A.removeFront());
System.out.println("A: " + A.toString());
A.add(-15, 2);
System.out.println("size: " + A.getSize() + " capacity: " + A.getCapacity() + " A: " + A.toString());
A.add(-18, 4);
System.out.println("size: " + A.getSize() + " capacity: " + A.getCapacity() + " A: " + A.toString());
A.add(-21, 1);
System.out.println("size: " + A.getSize() + " capacity: " + A.getCapacity() + " A: " + A.toString());
ourArray<String> S = new ourArray<String>(3, 5);
S.addFront("Hi");
S.add("There", 1);
S.addBack("you");
System.out.println("size: " + S.getSize() + " capacity: " + S.getCapacity() + " S: " + S.toString());
S.add("?", 3);
System.out.println("size: " + S.getSize() + " capacity: " + S.getCapacity() + " S: " + S.toString());
}
}
Step by step
Solved in 2 steps with 1 images