Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

232
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda