Thousand Separator

As a Systems Engineer at Tata Consultancy Services, I deliver exceptional software products for mobile and web platforms, using agile methodologies and robust quality maintenance. I am experienced in performance testing, automation testing, API testing, and manual testing, with various tools and technologies such as Jmeter, Azure LoadTest, Selenium, Java, OOPS, Maven, TestNG, and Postman.
I have successfully developed and executed detailed test plans, test cases, and scripts for Android and web applications, ensuring high-quality standards and user satisfaction. I have also demonstrated my proficiency in manual REST API testing with Postman, as well as in end-to-end performance and automation testing using Jmeter and selenium with Java, TestNG and Maven. Additionally, I have utilized Azure DevOps for bug tracking and issue management.
Given an integer n, add a dot (".") as the thousands separator and return it in string format.
LeetCode Problem -1556
class Solution {
// Method to add thousand separators to an integer
public String thousandSeparator(int n) {
String str = String.valueOf(n); // Convert integer n to a string
StringBuilder sb = new StringBuilder(); // StringBuilder to construct the result
int idx = 1; // Index to track positions in the reversed string
// Traverse the string from the end to the beginning
for(int i=str.length()-1; i>=0; i--){
// Add a dot after every third digit (except at the beginning) if the number has more than 3 digits
if(idx % 3 == 0 && idx != 0 && str.length() > 3){
sb.append(str.charAt(i)).append("."); // Append current character and dot
} else {
sb.append(str.charAt(i)); // Append current character without dot
}
idx++; // Increment the index
}
String preFinal = sb.reverse().toString(); // Reverse the StringBuilder and convert to string
return preFinal.replaceAll("^\\.+|\\.+$", ""); // Remove leading and trailing dots and return the final string
}
}




