Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
What happens when you add a double value to a String in java?
The “+” operator with a String acts as a concatenation operator.
Whenever you add a String value to a double using the “+” operator, both values are concatenated resulting a String object.
In-fact adding a double value to String is the easiest way to convert a double value to Strings.
Example
import java.util.Scanner;
public class StringsExample {
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
System.out.println("Enter a double value: ");
double d = sc.nextDouble();
System.out.println("Enter a String value: ");
String str = sc.next();
//Adding double and String
String result = str+d;
System.out.println("Result of the addition "+result);
}
}
}
Output
Enter a double value: 245.5474 Enter a String value: test Result of the addition test245.5474
Advertisements
