image_2021-10-31_02-54-09.png
52 KB
#N1556. Thousand Separator
problem link=>https://leetcode.com/problems/thousand-separator/
#solution
problem link=>https://leetcode.com/problems/thousand-separator/
#solution
class Solution {
public String thousandSeparator(int n) {
String str=String.valueOf(n);
int xonalar=str.length();
String ans="";
if(xonalar<=3) return str;
if(xonalar>3&&xonalar%3!=0)
ans+=str.substring(0, xonalar%3)+".";
int index=xonalar%3+2;
while(index<=xonalar){
ans+=str.substring(index-2, index+1)+".";
index+=3;
}
return ans.substring(0, ans.length()-1);
}
}