Iam_Sandeep

Untitled

Apr 20th, 2026
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.58 KB | None | 0 0
  1. class AdditionMagic {
  2.    
  3.     // 1. Concatenates an integer and a String
  4.     public String add(int a, String b) {
  5.         return a + b;
  6.     }
  7.  
  8.     // 2. Adds two doubles and rounds to 2 decimal places
  9.     public String add(double a, double b) {
  10.         double sum = a + b;
  11.         // Multiply by 100, round to nearest whole number, then divide by 100.0
  12.         double roundedSum = Math.round(sum * 100.0) / 100.0;
  13.         return String.valueOf(roundedSum);
  14.     }
  15.  
  16.     // 3. Concatenates two Strings
  17.     public String add(String a, String b) {
  18.         return a + b;
  19.     }
  20. }
  21.  
Advertisement
Add Comment
Please, Sign In to add comment