Smallest integer after only integers can be expressed IEEE 754
Date : March 29 2020, 07:55 AM
around this issue Presuming that “after” refers to numbers with greater magnitude and not later in time, 223 for 32-bit binary floating-point and 252 for 64-bit binary floating-point. (These are float and double in the most common programming language implementations with those type names.) This is because the significands of the 32-bit and 64-bit formats have 24 and 53 bits, respectively. So, in the 32-bit format, if the high bit is scaled to 222 by the exponent, the low bit would be 2–1 (from 22 to –1, inclusive, is 24 positions). Since the significand contains a bit scaled to a non-integer value, the complete represented value could be a non-integer. If the high bit is scaled to 223 or greater, then the low bit has value at least 20.
|
Find smallest integer in array which is a divisor of all previous integers
Date : March 29 2020, 07:55 AM
wish help you to fix your issue an divides all previous elements if and only if it divides the greatest common divisor of those elements. So you need to keep track of gcd(a1, a2, ..., an) and the minimum an for which an | gcd(...).
|
Comparing integers and creating the smallest integer possible from the digits of the given integers
Date : March 29 2020, 07:55 AM
Any of those help I need to write the following method: accepts two integer parameters and returns an integer. If either integer is not a 4 digit number than the method should return the smaller integer. Otherwise, the method should return a four digit integer made up of the smallest digit in the thousands place, hundreds place, tens place and ones place. We cannot turn the integers into Strings, or use lists, or arrays. public static int biggestLoser(int a, int b) {
if (a < 1000 || a >= 10000 || b < 1000 || b >= 10000) {
return Math.min(a, b);
} else {
// both a and b are four digits
int result = 0 ;
int multiplier = 1 ;
for (int digit = 0; digit < 4; digit++) {
int nextDigit = Math.min(a % 10, b % 10);
result = result + nextDigit * multiplier ;
multiplier = multiplier * 10 ;
a = a / 10 ;
b = b / 10 ;
}
return result ;
}
}
public static final int NUM_DIGITS = 4 ;
public static final int MAX = (int) Math.pow(10, NUM_DIGITS) ;
public static final int MIN = MAX / 10 ;
public static int biggestLoser(int a, int b) {
return (a < MIN || a >= MAX || b < MIN || b >= MAX) ? Math.min(a, b) :
IntStream.iterate(1, multiplier -> multiplier * 10).limit(NUM_DIGITS)
.map(multiplier -> Math.min((a / multiplier) % 10, (b / multiplier) % 10) * multiplier )
.sum();
}
|
Read a list of nonnegative integers and to display the largest integer, the smallest integer and the average of all the
Date : March 29 2020, 07:55 AM
I hope this helps . I have encountered some problems with the calculating of largest and smallest number... If the first number I entered is a larger number than the 2nd number input, it will not record the 1st number into the largest... , Do it like this: public static void main(String[] args) {
int smallest = Integer.MAX_VALUE;
int largest = 0;
int number;
double totalAvg = 0;
double totalSum = 0;
int count = 0;
Scanner kb = new Scanner(System.in);
System.out.println("Enter few integers (Enter negative numbers to end input) :");
while (true) { //LOOP till user enter "-1"
number = kb.nextInt();
//Condition for the loop to break
if (number <= -1) {
System.out.println("End Of Input");
break;
} else {
count = count + 1;
}
if (number < smallest) { //Problem 1 : If 1st input num is bigger than 2nd input num,
smallest = number; // largest num will not be recorded..
}
//REMOVED ELSE ADDED another IF
if (number > largest){
largest = number;
}
totalSum = totalSum + number;
totalAvg = (totalSum / count);
}
System.out.println("The smallest number you have entered is : " + smallest);
System.out.println("The largest number you have entered is : " + largest);
System.out.println("The total sum is : " + totalSum);
System.out.println("The total average is : " + totalAvg);
System.out.println("Count : " + count);
} // PSVM
|
Find the second smallest integer in an array. Returns wrong value for 2nd smallest integer
Tag : java , By : user93312
Date : March 29 2020, 07:55 AM
|