62,614
社区成员
发帖
与我相关
我的任务
分享
" test \\abc \"hello \\ \" "
1 2 3 4 5 6 7
package net.csdn.java;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
public class Test {
/**
* "regex" // hello
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
String name = "大/*家" + "好*/啊" + "// comment"; // comment
URL url = new URL("http://localhost:8080/test/ReceiveData"); // request URL
HttpURLConnection con = (HttpURLConnection)url.openConnection();
con.setDoInput(true);
con.setDoOutput(true);
con.setRequestMethod("POST"); // set POST request method
/* 请求头 // content-type */
con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
con.setUseCaches(false);
// add request parameters
DataOutputStream dos = new DataOutputStream(con.getOutputStream());
dos.writeBytes("name=" + URLEncoder.encode(name, "gbk"));
dos.writeBytes("&age=" + URLEncoder.encode("1234", "gbk"));
dos.flush();
dos.close();
System.out.println(con.getResponseCode());
con.disconnect();
}
/**
* 计算 2 + 22 + 222 的值
* @param num 不断增加的数字
* @param digit 总共的位数
* @return
*/
public static int add(int num, int digit) {
int n = 0;
for(int i = 1; i <= digit; i++) {
n = n * 10 + i * num;
}
return n;
}
public static void printDiamond(int line, boolean isSolid) {
boolean b = true;
for(int k = line / 2, i = -k; i <= k; i++) {
for(int j = -k, m = k - Math.abs(i); j <= m; j++) {
if(isSolid) {
// 实心菱形
b = Math.abs(j) <= m;
} else {
// 空心菱形
b = Math.abs(j) == m;
}
System.out.print(b ? '*' : ' ');
}
System.out.println();
}
}
/**
* 计算 num 的阶乘
* @param num
* @return
*/
private static int factorial(int num) {
return factorial(1, num);
}
/**
* 计算 start * (start + 1) * (start + 2) * ... * end 的值
* @param start 阶乘的起始数
* @param end 阶乘的结束数
* @return
*/
private static int factorial(int start, int end) {
if(start > end) {
int t = start;
start = end;
end = t;
}
int result = start > 0 ? start : 1;
// calculate factorial
while(end > start) {
result *= end--;
}
return result;
}
}