Karthikeya Boyini has Published 2383 Articles

Convert double primitive type to a Double object in Java

karthikeya Boyini

karthikeya Boyini

Updated on 26-Jun-2020 08:52:45

6K+ Views

To convert double primitive type to a Double object, you need to use Double constructor.Let’s say the following is our double primitive.// double primitive double val = 23.78;To convert it to a Double object, use Double constructor.// Double object Double ob = new Double(val);Example Live Demopublic class Demo {    public ... Read More

Double isNaN() method in Java

karthikeya Boyini

karthikeya Boyini

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

116 Views

The java.lang.Double.isNan() method returns true if the specified number is a Not-a-Number (NaN) value, false otherwise.Let’s say the following are our Double values.Double val1 = new Double(3/0.); Double val2 = new Double(0/0.);Now, we will use the isNan() method to check whether the number is a NaN or not.val1.isNaN(); val2.isNaN()The following ... Read More

Java Program to convert a String to a float type Number

karthikeya Boyini

karthikeya Boyini

Updated on 26-Jun-2020 08:47:30

154 Views

Use the parseFloat() method in Java to convert a String to a float type.Let’s say we have the following string.String str = "111.8";Now, the Float.parseFloat() method will convert it to a float type number.float floatVal = Float.parseFloat(str);The following is the complete example with output.Example Live Demopublic class Demo {    public ... Read More

Check two float arrays for equality in Java

karthikeya Boyini

karthikeya Boyini

Updated on 26-Jun-2020 08:45:58

115 Views

To check two float arrays for equality, use the Arrays.equals() method.In our example, we have the following two float arrays.float[] floatVal1 = new float[] { 3.2f, 5.5f, 5.3f }; float[] floatVal2 = new float[] { 3.2f, 5.5f, 5.3f };Let us now compare them for equality.if (Arrays.equals(floatVal1, floatVal2)) { System.out.println("Both are ... Read More

Initialization of static variables in C

karthikeya Boyini

karthikeya Boyini

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

4K+ Views

When static keyword is used, variable or data members or functions can not be modified again. It is allocated for the lifetime of program. Static functions can be called directly by using class name.Static variables are initialized only once. Compiler persist the variable till the end of the program. Static ... Read More

return statement vs exit() in main() C++

karthikeya Boyini

karthikeya Boyini

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

1K+ Views

return statementThe return statement terminates the execution of function and it returns the control to the calling function. It calls the constructor as well as the destructor. It returns an integer value for “int main()”.The following is the syntax of return statement.return expression;Here, expression − The expression or any value ... Read More

C++ Program to Find Factorial of Large Numbers

karthikeya Boyini

karthikeya Boyini

Updated on 26-Jun-2020 08:40:22

1K+ Views

The following is an example to find the factorial.Example#include using namespace std; int fact(unsigned long long int n) {    if (n == 0 || n == 1)    return 1;    else    return n * fact(n - 1); } int main() {    unsigned long long int n;    coutn;    cout

C++ Program to Check Whether a Number can be Expressed as Sum of Two Prime Numbers

karthikeya Boyini

karthikeya Boyini

Updated on 26-Jun-2020 08:38:49

972 Views

The following is an example to check whether a number can be expressed as sum of two prime numbers.Example Live Demo#include using namespace std; int func(int num) {    int i;    int flag = 1;    for(i = 2; i num;    for(i = 2; i

Swap two variables in one line in C/C+

karthikeya Boyini

karthikeya Boyini

Updated on 26-Jun-2020 08:37:21

1K+ Views

Here is an example of swapping in C language, Example Live Demo#include int main() {    int a = 28, b = 8;    a += b -= a = b - a; // method 1    printf("After Swapping : %d\t%d", a, b);    (a ^= b), (b ^= a), ... Read More

Java Program to display previous day from GregorianCalender

karthikeya Boyini

karthikeya Boyini

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

304 Views

For GregorianCalendar class, import the following package.import java.util.GregorianCalendar;Create an object.GregorianCalendar cal = (GregorianCalendar) GregorianCalendar.getInstance();Now, use the following field and add() method with a negative one (-1) to display the previous day.cal.add((GregorianCalendar.DATE), -1)Example Live Demoimport java.util.Calendar; import java.util.GregorianCalendar; public class Demo {    public static void main(String[] a) {       ... Read More

Advertisements