Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class ValueOfExample {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6. System.out.print("Enter first number: ");
  7. String firstValue = scanner.next();
  8. System.out.print("Enter second number: ");
  9. String secondValue = scanner.next();
  10.  
  11. int indexFirstValue = firstValue.indexOf(",");
  12. if (indexFirstValue >= 0) {
  13. System.out.println("Comma in first number is located at position: " + firstValue.indexOf(","));
  14. }
  15.  
  16. int indexSecondValue = secondValue.indexOf(",");
  17. if (indexSecondValue >= 0) {
  18. System.out.println("Comma in second number is located at position: " + secondValue.indexOf(","));
  19. }
  20.  
  21. System.out.println(Double.valueOf(firstValue.replace(",", ".")) + " + " + Double.valueOf(secondValue.replace(",", ".")) + " = "
  22. + (Double.valueOf(firstValue.replace(",", ".")) + Double.valueOf(secondValue.replace(",", "."))));
  23.  
  24. }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement