• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

201
Views
Why there is no compilation error when I am using different data types for switch expression and case value in this case
public class Conditionsif {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        int day=1;
        switch(day){
        case '1':
            System.out.println("Monday");
            break;
        
        }
        
    }

}

There is no compilation error in above though switch expression is integer data type and case value is character

about 3 years ago · Santiago Trujillo
1 answers
Answer question

0

Its because of implicit casting ascii value of a is 97

 switch(97){
           case 'a': System.out.println("a"); break;
           case 'b': System.out.println("b"); break;
           case 'c': System.out.println("c"); break;
 }
about 3 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 Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error