Saturday, June 22, 2019

what are the data types we cannot use in switch statement?

Problem statement:
what are the data types you cannot use as a parameter variable for switch statements in Java 8?

Following are the data types we cannot use as an input parameter variable for switch() statements.
  1. long
  2. float
  3. double
Error: Incompatible type found long, float and double.

public class SwitchStatement {
    public static void main(String[] args) {
        double d = 10.5d;
        switch (d) {
            case 10.5d:
                System.out.println("double");
                break;            
            default:
                System.out.println("default");
                break;
        }
    }
}
Error: Incompatible types. Found: 'double'

No comments:

Post a Comment

Blueprint for self-improvement

To learn faster: Make the process fun To understand yourself : Write To understand the world better : Read To build deeper connection : Lis...