Java switch-case fall-through causes code error [closed]

3 weeks ago 18
ARTICLE AD BOX

I am solving the Codeforces "Bit++" problem using Java.

The program should decrease a variable when the input is "--X",but in this case the proplem happens named Fall-through error.

Here is my code ->>

import java.util.Scanner;

public class Main {

public static void main(String[] args) { Scanner input = new Scanner( System.in ); int sum = 0; int n = input.nextInt(); for( int i = 1; i <= n; i++ ) { String x = input.next(); switch( x ) { case "X++": sum = sum + 1; break; case "X--": sum = sum - 1; break; case "++X": sum = 1 + sum; break; case "--X": sum = sum - 1; } } System.out.println(sum); }

}

Read Entire Article