All pastes #935153 Raw Edit

Unnamed

public java v1 · immutable
·published 2008-03-09 11:58 UTC
rendered paste body
	public static int varmista(String varmistus) {		/**		 * As a default, set confirmation to 'no'.		 */		int varmista = 2;		boolean onValidi;		/**		 * Print the confirmation message.		 */		do {			onValidi = true;			System.out.println("\n" + varmistus);			/**			 * This will check that the users answer is integer.			 */			try {				varmista = lue.nextInt();			} 			/**			 * This will catch the exception: if user inputs something that is not integer while 			 * integer is being expected, InputMismatchException occurs.			 */			catch(InputMismatchException IME) {				System.out.println("Vastaa kokonaisluvulla 1 tai 2");				onValidi = false;			};			/**			 * If user answered yes, then value of varmista will be changed to 1			 */		}		while(onValidi == false);		if(varmista == 1) {			varmista = 1;		}		/**		 * Return the answer.		 */		return varmista;	}