Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

235
Views
Using Switch To Seperate Outputs Of Different Letters

Is there any way that if a user enters any letter except T, M, or S that it will output other? Or do I have to make a case for every letter and put other? Is there any way to group them for the 'case.' Like for instance,

case "A - Q":
  System.out.print("Other");
  break;

Obviously you cant do that but something along those lines?

import java.util.Scanner;

public class SwitchPractice 
  {
  public static void main(String args[]) 
    {
    Scanner input = new Scanner(System.in);
    String employeeCode;
    System.out.print("Enter employees code: ");
    employeeCode = input.next();
    switch (employeeCode)
      {
      case "T":
          System.out.print("Technician");
          break;
      case "S":
          System.out.print("Sales");
          break;
     case "M":
          System.out.print("Marketing");
          break;
     case "?":
          System.out.print("OTHER!");
 } } }
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Use a default case. For example:

import java.util.Scanner;

public class SwitchPractice 
  {
  public static void main(String args[]) 
    {
    Scanner input = new Scanner(System.in);
    String employeeCode;
    System.out.print("Enter employees code: ");
    employeeCode = input.next();
    switch (employeeCode)
      {
      case "T":
          System.out.print("Technician");
          break;
      case "S":
          System.out.print("Sales");
          break;
     case "M":
          System.out.print("Marketing");
          break;
     default:
          System.out.print("OTHER!");
          break;
     }
   }
 }

This default case will execute whenever the letter is not "T", "M", or "S".

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!