Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.text.NumberFormat;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- char Gen = 0;
- int Age = 0, ReAge = 0;
- boolean isNotCorrect = true;
- Scanner scan = new Scanner( System.in );
- System.out.println( "This program will find the recommended age for marriage" );
- System.out.println( "Man or Woman ? ENTER M if you are a man or W if you are a woman and your age." );
- do {
- try {
- Gen = scan.next().charAt(0);
- Age = scan.nextInt();
- if ((Gen != 'M' && Gen != 'W') && (Age < 16 || Age > 100)) {
- System.out.println("Enter existing gender");
- System.out.println("Enter acceptable age(16-100)");
- }
- else if (Gen != 'M' && Gen != 'W') {
- System.out.println("Enter existing gender");
- }
- else {
- isNotCorrect = false;
- if (Age < 16 || Age > 100) {
- System.out.println("Enter acceptable age(16-100)");
- isNotCorrect = true;
- }
- else {
- isNotCorrect = false;
- }
- }
- } catch(Exception err ){
- System.out.print("Data entered incorrectly, please re-enter");
- scan.nextLine();
- }
- }while ( isNotCorrect );
- if ( Gen == 'M' )
- ReAge = Age / 2 + 7;
- else
- ReAge = Age * 2 - 14;
- System.out.print( "Recommended age of a candidate for marriage : " + ReAge);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement