Hello, I've been doing this task for a while now and I am currently having trouble. The program supposed to print Mr. or Mrs. based on the gender on the user input. example is below.
Input:
Enter your gender (Male/Female):
Male
Output:
Welcome, Mr. (name) etc and your gender is male.
however the output becomes " Welcome, male (name)"
package jksdj; import java.util.Scanner; public class JavaActivity2 { public static void main(String[] args) { Scanner name1 = new Scanner(System.in); System.out.println("Enter your first name: "); String firstName = name1.nextLine(); Scanner name2 = new Scanner(System.in); System.out.println("Enter your middle initial: "); char middleInitial = name2.next().charAt(0); Scanner name3 = new Scanner(System.in); System.out.println("Enter your last name: "); String lastName = name3.nextLine(); Scanner bday = new Scanner(System.in); System.out.println("Enter your Birthdate (mm/dd/yyyy): "); String birthDate = bday.nextLine(); Scanner housenum = new Scanner(System.in); System.out.println("Enter the number of people in your household: "); int peopleHouse = housenum.nextInt(); Scanner salary = new Scanner(System.in); System.out.println("Enter your annual salary: "); double annualSalary = salary.nextDouble(); String Usergender = ""; Scanner gender = new Scanner(System.in); System.out.println("Enter your gender (Male/Female): "); Usergender = gender.nextLine(); if (Usergender.equalsIgnoreCase("Male") || Usergender.equalsIgnoreCase("male")) { System.out.println("Mr. "); } else { System.out.println("Ms. "); } Scanner address = new Scanner(System.in); System.out.println("Enter your address: "); String userAddress = address.nextLine(); String[] bdayArray = birthDate.split("/", 3); int currentYear = 2022; int age = currentYear - Integer.parseInt(bdayArray[2]); System.out.println("Welcome," + Usergender + " " + firstName + " " + middleInitial + ". " + lastName + " to our system. Your birthdate is " + birthDate + ",and you are " + age + " years old, your gender is " + Usergender + " and you reside in " + userAddress + ". The total number of people in your household is " + peopleHouse + " and your annual salary is Php " + annualSalary + "."); } }