Remove Last Comma of Number in Java:
Explanation :
Here We Take A Input By User In Number And Print With Seprated By Comma.
- Input : 12345
- Output: 5,4,3,2,1
import java.util.Scanner;
public class PrintInput {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int num,digit;
System.out.println("Enter the Number:");
num = scan.nextInt();
while(num>0){
digit = num%10;
num = num/10;
System.out.print(digit);
if(num>0){ //it is used for remove last comma
System.out.print(",");
}
}
}
}
Remove last comma of Number and Print in Java - CodexRitik
Reviewed by CodexRitik
on
July 24, 2020
Rating:
No comments: