I just want to know how I can get my program to end when the user inputs "0." By using: System.exit(0);
import java.util.Scanner; public class TestCode { public static void main (String [ ]args ) { Scanner console =new Scanner(System.in); System.out.println("To exit program input 0"); for (int y = 1; y < 11; y++ ){ // Executes output 10 times System.out.println("Enter the year please:"); int year = console.nextInt(); if (year >= 1900) { boolean answer = isLeapYear (year); if(answer) { System.out.println("The given year is a leap year"); } else { System.out.println("The given year is not a leap year"); } } else { System.out.println("Value is invalid! Number is less than 1900."); } } } public static boolean isLeapYear(int y) //y = year { if ((y % 400 == 0) || ((y % 4 == 0) && (y % 100 != 0))) // Algorithim used for calculating leap years. { return true; } else { return false; } } }
Any help is appreciated, thank you for your time .