小编Pat*_*zyk的帖子

需要常量表达式?(Java switch语句)

我不知道是什么导致了这个错误.我的老师和我老去了,找不到什么问题.

import java.util.Scanner;
public class MailAssignment
{
public static void main(String [] args){

    Scanner userinput = new Scanner(System.in);
    char p;
    char f;
    double price = 0;
    System.out.println("First class or priority?");
    char type = userinput.next().charAt(0);
    System.out.println("How much does the package weigh? (in ounces)");
    double weight = userinput.nextDouble();

    switch (type){
     case p:
     if (weight > 16)
        price = weight * 3.95;

        else if (weight > 32) 
            price = (1.20 * (weight / 16));
       else
            price = 3.50 * weight;


        break;


     case f: …
Run Code Online (Sandbox Code Playgroud)

java switch-statement

3
推荐指数
1
解决办法
3万
查看次数

标签 统计

java ×1

switch-statement ×1