Rispondi a: Es 6 Lez 10

Blog Forum Java Es 6 Lez 10 Rispondi a: Es 6 Lez 10

#5569
ANTONIO PAGANO
Ospite
Up
0
Down
::

Ciao, l’errore sulle variabili booleane è che, una volta create, non vengono mai usate.
Di seguito una possibile soluzione:

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		System.out.println("Inserisci il numero di un anno, e saprai se è bisestile o meno");
		int a = scan.nextInt();

		
		float r = a % 400; // riferimento ai secolari
		float s = a % 4; // riferimento ai bisestili
		float t = a % 100;
		
		boolean bisestile = false;
		
		if (r == 0) { // divisibile per 400
			bisestile = true;
		} else {
			
			if (s == 0 && t != 0) {// divisibile per 4 ma non per 100
				bisestile = true;
			}

		}
		if (bisestile) {
			System.out.println(a + " è un anno bisestile");
		} else
			System.out.println(a + " NON è un anno bisestile");

	}