If statement always giving the same answer

前端 未结 7 535
-上瘾入骨i
-上瘾入骨i 2020-12-12 03:26
import java.util.Scanner;

class Practice {

public static void main(String args[]) {

    System.out.println(\"Enter the number of treats you have:\");
    Scanner          


        
7条回答
  •  盖世英雄少女心
    2020-12-12 03:59

    Few things to note and to add to the listed answers

    • Just one scanner is enough Scanner inputScanner = new Scanner(System.in);
    • Braces around (...Scanner.nextInt()); is not really necessary
    • You may need to consider a non zero check for hamsters !
    • Handle Non Ints & -ve numbers in the input
    • else if(){} is not required when if(){} has only single boolean check , just an else{ is sufficient

提交回复
热议问题