KiKi访问网站,得到HTTP状态码,但他不知道什么含义,BoBo老师告诉他常见HTTP状态码:200(OK,请求已成功),202(Accepted,服务器已接受请求,但尚未处理。)400(Bad Request,请求参数有误),403(Forbidden,被禁止),404(Not Found,请求失败),500(Internal Server Error,服务器内部错误),502(Bad Gateway,错误网关)。
KiKi访问网站,得到HTTP状态码,但他不知道什么含义,BoBo老师告诉他常见HTTP状态码:200(OK,请求已成功),202(Accepted,服务器已接受请求,但尚未处理。)400(Bad Request,请求参数有误),403(Forbidden,被禁止),404(Not Found,请求失败),500(Internal Server Error,服务器内部错误),502(Bad Gateway,错误网关)。
多组输入,一行,一个整数(100~600),表示HTTP状态码。
针对每组输入的HTTP状态,输出该状态码对应的含义,具体对应如下:
200-OK
202-Accepted
400-Bad Request
403-Forbidden
404-Not Found
500-Internal Server Error
502-Bad Gateway
200
OK
import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); // 注意 hasNext 和 hasNextLine 的区别 while (in.hasNextInt()) { // 注意 while 处理多个 case int a = in.nextInt(); if(a==200){ System.out.println("OK"); } if(a==202){ System.out.println("Accepted"); } if(a==400){ System.out.println("Bad Request"); } if(a==403){ System.out.println("Forbidden"); } if(a==404){ System.out.println("Not Found"); } if(a==500){ System.out.println("Internal Server Error"); } if(a==502){ System.out.println("Bad Gateway"); } } } }
import java.util.*; public class Main{ public static void main(String[] args){ Scanner sc=new Scanner(System.in); Map<Integer,String> type=new HashMap<>(); type.put(200,"OK"); type.put(202,"Accepted"); type.put(400,"Bad Request"); type.put(403,"Forbidden"); type.put(404,"Not Found"); type.put(500,"Internal Server Error"); type.put(502,"Bad Gateway"); while(sc.hasNextInt()) System.out.println(type.get(sc.nextInt())); } }
import java.util.*; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while(scanner.hasNext()){ int httpStatusCode = scanner.nextInt(); switch(httpStatusCode){ case 200: System.out.println("OK"); break; case 202: System.out.println("Accepted"); break; case 400: System.out.println("Bad Request"); break; case 403: System.out.println("Forbidden"); break; case 404: System.out.println("Not Found"); break; case 500: System.out.println("Internal Server Error"); break; case 502: System.out.println("Bad Gateway"); break; default: System.out.println("No this HTTP Status Code!"); break; } } } }
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while(sc.hasNext()){ int n = sc.nextInt(); switch (n) { case 200 : System.out.println("OK"); break; case 202 : System.out.println("Accepted"); break; case 400 : System.out.println("Bad Request"); break; case 403 : System.out.println("Forbidden"); break; case 404 : System.out.println("Not Found"); break; case 500 : System.out.println("Internal Server Error"); break; case 502 : System.out.println("Bad Gateway"); break; default: System.out.println("wrong"); } } } }
import java.util.*; public class Main{ public static void main(String args[]){ Scanner input=new Scanner(System.in); while(input.hasNext()){ int code=input.nextInt(); switch(code){ case 200: System.out.println("OK"); break; case 202: System.out.println("Accepted"); break; case 400: System.out.println("Bad Request"); break; case 403: System.out.println("Forbidden"); break; case 404: System.out.println("Not Found"); break; case 500: System.out.println("Internal Server Error"); break; case 502: System.out.println("Bad Gateway"); break; } } input.close(); } }
import java.util.Scanner; /** * * @Title HTTP状态码 * @Description KiKi访问网站,得到HTTP状态码,但他不知道什么含义,BoBo老师告诉他常见HTTP状态码: * 200(OK,请求已成功), * 202(Accepted,服务器已接受请求,但尚未处理。) * 400(Bad Request,请求参数有误), * 403(Forbidden,被禁止), * 404(Not Found,请求失败), * 500(Internal Server Error,服务器内部错误), * 502(Bad Gateway,错误网关)。 * 输入描述: * 多组输入,一行,一个整数(100~600),表示HTTP状态码。 * 输出描述: * 针对每组输入的HTTP状态,输出该状态码对应的含义,具体对应如下: * 200-OK * 202-Accepted * 400-Bad Request * 403-Forbidden * 404-Not Found * 500-Internal Server Error * 502-Bad Gateway * @author weijunfu<ijunfu @ qq.com> * @date 2022/03/17 08:53 * @version 1.0.0 * */ public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); while(in.hasNextLine()) { int status = Integer.parseInt(in.nextLine()); switch (status) { case 200: System.out.println("OK"); break; case 202: System.out.println("Accepted"); break; case 400: System.out.println("Bad Request"); break; case 403: System.out.println("Forbidden"); break; case 404: System.out.println("Not Found"); break; case 500: System.out.println("Internal Server Error"); break; case 502: System.out.println("Bad Gateway"); break; } } } }
import java.util.Scanner; public class Main{ public static void main(String[] args) { Scanner scan = new Scanner(System.in); while(scan.hasNext()) { int state = scan.nextInt(); int[] httpstate = {200,202,400,403,404,500,502}; String[] result = {"OK","Accepted","Bad Request","Forbidden","Not Found","Internal Server Error","Bad Gateway"}; for(int i=0;i<httpstate.length;i++){ if(state == httpstate[i]){ System.out.println(result[i]); break; } } } } }
import java.util.*; public class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); while(sc.hasNext()){ int num = sc.nextInt(); if(num == 200) System.out.println("OK"); if(num == 202) System.out.println("Accepted"); if(num == 400) System.out.println("Bad Request"); if(num == 403) System.out.println("Forbidden"); if(num == 404) System.out.println("Not Found"); if(num == 500) System.out.println("Internal Server Error"); if(num == 502) System.out.println("Bad Gateway"); } } }
import java.util.HashMap; import java.util.Map; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); Map<Integer,String> map = new HashMap<>(16); map.put(200,"OK"); map.put(202,"Accepted"); map.put(400,"Bad Request"); map.put(403,"Forbidden"); map.put(404,"Not Found"); map.put(500,"Internal Server Error"); map.put(502,"Bad Gateway"); while (sc.hasNext()) { int state = sc.nextInt(); System.out.println(map.get(state)); } } }