"power-hungry foobar solution in java" Code Answer's
You're definitely familiar with the best coding language Java that developers use to develop their projects and they get all their queries like "power-hungry foobar solution in java" answered properly. Developers are finding an appropriate answer about power-hungry foobar solution in java related to the Java coding language. By visiting this online portal developers get answers concerning Java codes question like power-hungry foobar solution in java. Enter your desired code related query in the search bar and get every piece of information about Java code related question on power-hungry foobar solution in java.
power-hungry foobar solution in java
package com.google.challenges;
import java.math.BigInteger;
public class Answer {
public static String answer (int[] xs){
BigInteger result = new BigInteger("1");
int xsLen = xs.length, pos = 0,ng=0;
int[] negatives = new int[xsLen];
if (xsLen == 1){
return Integer.toString(xs[0]);
}
for (int n = 0;n < xsLen;n++){
int val = xs[n];
if (val == 0){
continue;
}
if (val > 0){
result = result.multiply(new BigInteger(Integer.toString(val)));
ng++;
} else {
negatives[pos] = val;
pos++;
}
}
if(ng==0)
{
int l=0;
return Integer.toString(l);
}
if ((pos % 2) == 0){
for (int i = 0;i < pos;i++){
result = result.multiply(new BigInteger(Integer.toString(negatives[i])));
}
} else {
int min = -1000; int mPos = -1;
for (int i = 0;i < pos;i++){
if(negatives[i] > min){
min = negatives[i];
mPos = i;
}
}
for (int j = 0;j < pos;j++){
if(j == mPos){
continue;
}
result = result.multiply(new BigInteger(Integer.toString(negatives[j])));
}
}
return result.toString();
}
}
Source: stackoverflow.com
All those coders who are working on the Java based application and are stuck on power-hungry foobar solution in java can get a collection of related answers to their query. Programmers need to enter their query on power-hungry foobar solution in java related to Java code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about power-hungry foobar solution in java for the programmers working on Java code while coding their module. Coders are also allowed to rectify already present answers of power-hungry foobar solution in java while working on the Java language code. Developers can add up suggestions if they deem fit any other answer relating to "power-hungry foobar solution in java". Visit this developer's friendly online web community, CodeProZone, and get your queries like power-hungry foobar solution in java resolved professionally and stay updated to the latest Java updates.