java - 给定一个 int 变量状态,编写一个 switch 语句,根据状态单独打印出上述列表中的适当标签
问题描述
HTTP 是管理 Web 服务器和 Web 客户端(即浏览器)之间通信的协议。协议的一部分包括服务器返回的状态代码,用于告诉浏览器其最近的页面请求的状态。下面列出了一些代码及其含义:
200,OK(已完成) 403,禁止 404,未找到 500,服务器错误
给定一个 int 变量状态,编写一个 switch 语句,根据状态单独打印出上述列表中的适当标签。
这就是我的代码,但它仍然无法正常工作,我不确定为什么。
switch ( status ){
case 200: System.out.println("OK(fulfilled)");
break;
case 403: System.out.println("forbidden");
break;
case 404: System.out.println("not found");
break;
case 500: System.out.println("server error");
break;
}
我得到的错误是“_stdout 的值不正确”。
解决方案
你能发布你的整个源代码吗?您是否尝试过使用如下所示的默认情况?
public void run() {
//enter a test case here to see if your console prints the output:
int status = readInt("Enter case here: ");
switch ( status ){
case 200: System.out.println("OK(fulfilled)");
break;
case 403: System.out.println("forbidden");
break;
case 404: System.out.println("not found");
break;
case 500: System.out.println("server error");
break;
//Try the default case here:
default:
break;
}
}
}
推荐阅读
- i2c - I2C 实用程序地址限制
- android - 如何在 1 小时内过期后获取有效的 Google ID 令牌
- javascript - React,将在父级创建的引用传递给子级
- javascript - 上传内容后刷新引导模式对话框的主体
- javascript - 大写独立反应道具
- javascript - 我如何获取用户 ID 服务器端?
- php - 将“Ymd H:i:s”转换为“dmY H:i:s”
- jwt - 为什么使用 Auth0 的 CouchDB JWT 身份验证对我不起作用?
- python - Python 应用程序看不到 PSQL 更改
- octave - 在 Octave 返回错误中以 ' 作为版权符号的矩阵的转置