U
U
Urukhayy2015-07-20 11:24:54
Programming
Urukhayy, 2015-07-20 11:24:54

Is this technique acceptable?

Greetings. Task: you need to perform an action with numbers that are not in the "forbidden" list.

switch(value) 
{
   case 1,6,2,61,2,612,321: {} // отметаем запрещённые числа для этого действия
   default: 
   {
      // производим действие с любыми другими
   }
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Eugene, 2015-07-20
@Urukhayy

Add a break to the first case

A
abs0lut, 2015-07-20
@abs0lut

What is the language?
p.s. i would do that

List<Integer> nums = new ArrayList<>(Arrays.asList(1,6,2,61,2,612,321));
if (nums.contains(value)) {
  //do stuff
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question