Samual Sam has Published 2492 Articles

Format floating point number in Java

Samual Sam

Samual Sam

Updated on 26-Jun-2020 08:53:34

1K+ Views

Let’s say we have the following two values.double val1 = 20.932; double val2 = 11.67;Let us now format these floating-point numbers. Firstly, we are formatting euler’s number withMath.exp(). After that, we have also evaluated log. The %.3f you can see here is what we used for formatting the numbers.System.out.printf("exp(%.3f) = ... Read More

Double isInfinite() method in Java

Samual Sam

Samual Sam

Updated on 26-Jun-2020 08:51:51

100 Views

The Double isInfinite() method returns true if this Double value is infinitely large in magnitude, false otherwise.Let’s say we have the following Double values.Double val1 = new Double(3/0.); Double val2 = new Double(0/0.);Use the isInfinite() method now. The return value is a boolean.val1.isInfinite(); val2.isInfinite();The following is the final example.Example Live Demopublic ... Read More

Convert from String to float in Java

Samual Sam

Samual Sam

Updated on 26-Jun-2020 08:48:08

895 Views

To convert String to float, use the valueOf() method.Let’s say we have the following string value.String str = "0.8";Converting the string to float.Float floatVal = Float.valueOf(str).floatValue();The following is the complete example.Example Live Demopublic class Demo {    public static void main(String args[]) {       String str = "0.8";   ... Read More

Java Program to compare Two Java float Arrays

Samual Sam

Samual Sam

Updated on 26-Jun-2020 08:46:48

120 Views

To compare Java float arrays, use the Arrays.equals() method. The return value is a boolean. Let’s say we have the following float arrays −float[] floatVal1 = new float[] { 3.2f, 5.5f, 5.3f }; float[] floatVal2 = new float[] { 8.3f, 8.8f, 9.2f }; float[] floatVal3 = new float[] { 6.2f, ... Read More

C function to Swap strings

Samual Sam

Samual Sam

Updated on 26-Jun-2020 08:44:51

598 Views

The following is an example to swap strings.Example Live Demo#include #include int main() {    char st1[] = "My 1st string";    char st2[] = "My 2nd string";    char swap;    int i = 0;    while(st1[i] != '\0') {       swap = st1[i];       ... Read More

exit() vs _Exit() in C/C++

Samual Sam

Samual Sam

Updated on 26-Jun-2020 08:43:18

510 Views

exit()The function exit() is used to terminate the calling function immediately without executing further processes. As exit() function calls, it terminates processes. It calls the constructor of class only. It is declared in “stdlib.h” header file in C language. It does not return anything.The following is the syntax of exit()void ... Read More

C++ Program to Compute Combinations using Factorials

Samual Sam

Samual Sam

Updated on 26-Jun-2020 08:39:33

810 Views

The following is an example to compute combinations using factorials.Example Live Demo#include using namespace std; int fact(int n) {    if (n == 0 || n == 1)    return 1;    else    return n * fact(n - 1); } int main() {    int n, r, result;    coutn;    coutr;    result = fact(n) / (fact(r) * fact(n-r));    cout

Print “Hello World” in C/C++ without using header files

Samual Sam

Samual Sam

Updated on 26-Jun-2020 08:36:48

611 Views

Generally, we use header files in C/C++ languages to access the built-in functions like int, char, string functions. The function printf() is also a built-in function which is declared in “stdio.h” header file and it is used to print any kind of data on console.Here is an example to print ... Read More

Determine day of week in month from Gregorian Calendar in Java

Samual Sam

Samual Sam

Updated on 26-Jun-2020 08:35:26

222 Views

To work with the GregorianCalendar class, import the following package −import java.util.GregorianCalendar;To get the day of week in month, use the following field −cal.get(Calendar.DAY_OF_WEEK_IN_MONTH)Above, cal is the GregorianCalendar object we created before −GregorianCalendar cal = new GregorianCalendar();The following is an example −Example Live Demoimport java.util.GregorianCalendar; import java.util.Calendar; import java.util.Date; public class ... Read More

Static functions in C

Samual Sam

Samual Sam

Updated on 26-Jun-2020 08:34:44

20K+ Views

A static function in C is a function that has a scope that is limited to its object file. This means that the static function is only visible in its object file. A function can be declared as static function by placing the static keyword before the function name.An example ... Read More

Advertisements