• java基础面试题:switch语句能否作用在byte上,能否作用在long上,能否作用在String上?


    package com.swift;
    
    public class Switch_Test {
    
        public static void main(String[] args) {
            /*
             * switch语句能否作用在byte上,能否作用在long上,能否作用在String上?
             */
            byte zijie = 3;
            System.out.println(zijie);
            long changzheng=3;
            switch (changzheng) {  //cannot switch on a value of type long.
            case 'a':
                System.out.println("this is a .");
                break;
            case 0:
                System.out.println("this is 0 int");
                break;
            case 3:
                System.out.println("this is 0 int");
                break;
            default:
                System.out.println("this is default.");
    
            }
        }
    
    }

    byte short char都是隐性int类型都可以,以及他们的包装类

    long 不行

    String也可以,要求case中也为String类型

    package com.swift;
    
    public class Switch_Test {
    
        public static void main(String[] args) {
            /*
             * switch语句能否作用在byte上,能否作用在long上,能否作用在String上?
             */
            byte zijie = 3;
            System.out.println(zijie);
            long changzheng=3;
            String str="abc";
            switch (str) {  //cannot switch on a value of type long.
            case "ab":
                System.out.println("this is a .");
                break;
            case "a":
                System.out.println("this is 0 int");
                break;
            case "abc":
                System.out.println("this is abc int");
                break;
            default:
                System.out.println("this is default.");
    
            }
        }
    
    }
  • 相关阅读:
    bzoj3237[Ahoi2013] 连通图
    bzoj3075[Usaco2013]Necklace
    bzoj1876[SDOI2009] SuperGCD
    bzoj3295[Cqoi2011] 动态逆序对
    BestCoder#86 E / hdu5808 Price List Strike Back
    bzoj2223[Coci 2009] PATULJCI
    bzoj2738 矩阵乘法
    poj 1321 -- 棋盘问题
    poj 3083 -- Children of the Candy Corn
    poj 2488 -- A Knight's Journey
  • 原文地址:https://www.cnblogs.com/qingyundian/p/8325464.html
Copyright © 2020-2023  润新知