-
Notifications
You must be signed in to change notification settings - Fork 0
/
Example24.java
63 lines (52 loc) · 1.74 KB
/
Example24.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import java.util.Scanner;
public class Example24 {
public static void main(String[]args)
{
Scanner input = new Scanner(System.in);
char gend,reply;
String fname,sname;
int age;
System.out.print("What is your gender (M or F)");
gend = input.next().charAt(0);
System.out.println("First name: ");
fname = input.nextLine();
System.out.println("Last name: ");
sname = input.nextLine();
System.out.print("Age: ");
age = input.nextInt();
if ( gend == 'F' && age >= 20)
{
System.out.print("Are you married please (y or n)?");
reply =input.next().charAt(0);
if(reply == 'y')
{
System.out.println("Then I shall call you Mrs " + fname + sname);
}
else
{
System.out.println("Then I shall call you Ms " + fname + sname);
}
}
else if ( gend == 'F' && age < 20)
{
System.out.println("Then I shall call you " + fname + sname);
}
else
{
System.out.println(" ");
}
if ( gend == 'M' && age >= 20)
{
System.out.print("Are you married please (y or n)?");
reply =input.next().charAt(0);
if(reply == 'y')
{
System.out.println("Then I shall call you Mr " + fname + sname);
}
else
{
System.out.println("Then I shall call you " + fname + sname);
}
}
}
}