public class ArrangeNum {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
List<Integer> numList = new ArrayList<Integer>();
List<Integer> posList = new ArrayList<Integer>();
List<Integer> negList = new ArrayList<Integer>();
Integer middleEle = -1;
int n;
System.out.println("Enter Size of an array: ");
n = input.nextInt();
System.out.println("Enter arra elements :");
for (int i = 0; i < n; i++ ) {
numList.add(input.nextInt());
}
for (int i = 0; i < n; i++) {
if (numList.get(i) == 0)
middleEle = 0;
else if ((numList.get(i)) > 0)
posList.add(numList.get(i));
else
negList.add(numList.get(i));
}
numList.clear();
numList.addAll(negList);
if (middleEle == 0)
numList.add(middleEle);
numList.addAll(posList);
System.out.println("New Number List -\n" + numList);
}
}
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
List<Integer> numList = new ArrayList<Integer>();
List<Integer> posList = new ArrayList<Integer>();
List<Integer> negList = new ArrayList<Integer>();
Integer middleEle = -1;
int n;
System.out.println("Enter Size of an array: ");
n = input.nextInt();
System.out.println("Enter arra elements :");
for (int i = 0; i < n; i++ ) {
numList.add(input.nextInt());
}
for (int i = 0; i < n; i++) {
if (numList.get(i) == 0)
middleEle = 0;
else if ((numList.get(i)) > 0)
posList.add(numList.get(i));
else
negList.add(numList.get(i));
}
numList.clear();
numList.addAll(negList);
if (middleEle == 0)
numList.add(middleEle);
numList.addAll(posList);
System.out.println("New Number List -\n" + numList);
}
}
No comments:
Post a Comment