Java - How to break out of while with hasNext() condition?

前端 未结 5 1200
被撕碎了的回忆
被撕碎了的回忆 2021-01-24 04:11

I am writing a simple program to calculate the average of a set of numbers. You get the numbers using Scanner, so I am using while loop with .has

5条回答
  •  别那么骄傲
    2021-01-24 04:49

    public static void main(String[] args){
    
        Scanner Input = new Scanner(System.in);
    
        System.out.println("Enter # to end ");
        while( !Input.hasNextInt("#"))// return true if u input value = its argument
        {
            //ur code
        }//end while
    

提交回复
热议问题