开发者社区 问答 正文

java 枚举类型怎么输出

public enum Weather{ Sunny,Rainy,Cloudy}
public String toString(){
return ; //这里怎么写才能输出是 Sunny或Rainy或Cloudy呢?
}

展开
收起
蛮大人123 2016-06-07 15:06:45 2316 分享 版权
1 条回答
写回答
取消 提交回答
  • 我说我不帅他们就打我,还说我虚伪
    
    import java.util.*;
    import java.lang.*;
    import java.io.*;
    
    /* Name of the class has to be "Main" only if the class is public. */
    class Ideone
    {
        public enum Weather{ Sunny,Rainy,Cloudy}
    
        public static void main (String[] args) throws java.lang.Exception
        {
            // your code goes here
            String s = Weather.Sunny.toString();
            System.out.println(s);
        }
    }
    2019-07-17 19:30:14
    赞同 展开评论
问答分类:
问答标签:
问答地址: