package gendergreeting; import java.util.Scanner; public class GenderGreeting { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter your gender (m/f): "); char gender = input.next().charAt(0); if (gender == 'm' || gender == 'M') { System.out.println("Hello Sir"); } else if (gender == 'f' || gender == 'F') { System.out.println("Hello Madam"); } else { System.out.println("Invalid input"); } } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter