Command line progress bar in Java

前端 未结 15 2039
[愿得一人]
[愿得一人] 2020-11-28 01:04

I have a Java program running in command line mode. I would like to display a progress bar, showing the percentage of job done. The same kind of progress bar you would see u

15条回答
  •  萌比男神i
    2020-11-28 01:33

    public class Main {
    
        public static void main(String[] args) throws Exception {
    
            System.out.println("Loading : ");
                int count =1;
                for(int j=1;j<150;j++){
    
                    System.out.print("\r");
                    if(count==1){
                        System.out.print("/");
                        count++;
                    }
                    else if(count==2){
                        System.out.print("|");
                        count++;
                    }
                    else if(count==3){
                        System.out.print("-");
                        count++;
                    }
                    else if(count==4){
                        System.out.print("\\");
                        count++;
                    }
                    else if(count==5){
                        System.out.print("|");
                        count++;
                    }
                    else
                        count = 1;
                Thread.sleep(200);
            }
    
            }
    
        }
    

提交回复
热议问题