Skip to content

Latest commit

 

History

History
25 lines (25 loc) · 475 Bytes

Q5.md

File metadata and controls

25 lines (25 loc) · 475 Bytes
public static void daoSoWhile(int n){
    List <Integer> list = new ArrayList<>();
    int flag = 0;
    if (n<0){
        n=-n;
        flag =1;
    }
    while (n!=0){
        list.add(n%10);
        if (list.get(0)==0){
            list.remove(0);    
        }
        n=n/10;
    }
    for (int j:list){
        if (flag ==1){
            System.out.print("-");
            flag ++;
        }
        System.out.print(j);
    }
    System.out.println(" ");
}