这是我的主要方法:
public static void main(String[] args) {
int[] myArray = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
for (int i = 0; i < myArray.length; i++) {
System.out.println(myArray[i]);
}
int[] sortedArray = InsertionSort.sorter(myArray);
for (int i = 0; i < sortedArray.length; i++) {
System.out.println(sortedArray);
}
}
Run Code Online (Sandbox Code Playgroud)
这是InsertionSort.sorter的样子:
public static int[] sorter(int[] a) {
return a;
}
Run Code Online (Sandbox Code Playgroud)
这是输出:
1
2
3
4
5
6
7
8
9
10
[I@7000a32b
[I@7000a32b
[I@7000a32b
[I@7000a32b
[I@7000a32b
[I@7000a32b
[I@7000a32b
[I@7000a32b
[I@7000a32b
[I@7000a32b …Run Code Online (Sandbox Code Playgroud) 我想做一个简单的post-redirect - 使用JSP.这就是我做到的.重要的Servlet是这样的:
public class PostRedirectGet extends HttpServlet {
public void doGet(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse)
throws ServletException, IOException {
getServletContext().getRequestDispatcher("/WEB-INF/getInformation.jsp")
.forward(httpServletRequest,httpServletResponse);
}
public void doPost(HttpServletRequest httpServletRequest,HttpServletResponse httpServletResponse)
throws IOException {
String firstName = httpServletRequest.getParameter("firstName");
HttpSession httpSession = httpServletRequest.getSession();
httpSession.setAttribute("firstName",firstName);
httpServletResponse.sendRedirect(getServletContext().getContextPath()+"/getFormData");
}
}
Run Code Online (Sandbox Code Playgroud)
因此,当对此Servlet(/ index)发出get请求时,我只显示表单所在的getInformation.jsp.
表单对同一个url(/ index)发出post请求,这次调用doPost.在这里我保持firstName如下所示:
String firstName = httpServletRequest.getParameter("firstName");
Run Code Online (Sandbox Code Playgroud)
然后我将用户重定向到/ getFormData.这是负责任的servlet:
public class Get extends HttpServlet {
public void doGet(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse)
throws ServletException, IOException {
String firstName = (String) …Run Code Online (Sandbox Code Playgroud) 所以我有这个方法:

那么为什么IntelliJ警告我那里不允许返回x,但是上面还可以吗?类ProjectElement的id也是long类型.
如果没有实际阅读,请不要回答这个问题.:)
这是我拥有的代码,它工作正常:
section .bss
bufflen equ 1024
buff: resb bufflen
whatread: resb 4
section .data
section .text
global main
main:
nop
read:
mov eax,3 ; Specify sys_read
mov ebx,0 ; Specify standard input
mov ecx,buff ; Where to read to...
mov edx,bufflen ; How long to read
int 80h ; Tell linux to do its magic
; Eax currently has the return value from linux system call..
add eax, 30h ; Convert number to ASCII digit
mov [whatread],eax ; Store how …Run Code Online (Sandbox Code Playgroud) 这是我的代码:
int main(){
char *p = "koraytugay";
printf("%s%i byte(s).\n", "Size of variable p:" ,sizeof(p));
printf("%s%i byte(s).\n\n", "Size of what p points to:" ,sizeof(*p));
char t[] = "koraytugay";
printf("%s%i byte(s).\n", "Size of variable t:" ,sizeof(t));
printf("%s%i byte(s).\n\n", "Size of what t points to:" ,sizeof(*t));
printf("%s%c\n", "Printing p[3]: ", p[3]);
printf("%s%c\n", "Printing t[3]: ", t[3]);
printf("%s",*(&p));
}
Run Code Online (Sandbox Code Playgroud)
我得到的输出是:
Size of variable p:8 byte(s).
Size of what p points to:1 byte(s).
Size of variable t:11 byte(s).
Size of what t points to:1 byte(s). …Run Code Online (Sandbox Code Playgroud) 这段代码:
int main(){
printf("The value of FLT_MAX is %.5f\n", FLT_MAX);
printf("The value of FLT_MIN is %.5f\n", FLT_MIN);
printf("A float takes %i bytes\n", sizeof(float));
float fx = -1.24;
printf("The value of fx is %f\n", fx);
}
Run Code Online (Sandbox Code Playgroud)
收益:
The value of FLT_MAX is 340282346638528859811704183484516925440.00000
The value of FLT_MIN is 0.00000
A float takes 4 bytes
The value of fx is -1.240000
Run Code Online (Sandbox Code Playgroud)
是float无符号数?为什么这是FLT_MIN 0另一方面我可以存储一个负值float?
我有一个名为islands.txt的文件,内容如下:
islandone
islandtwo
islandthree
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct island{
char *name;
struct island *previous;
} island;
void printIsland(island is){
printf("%s", is.name);
if(is.previous && is.previous->name[0] != '\0'){
printf("%s", is.previous->name);
}
}
int main(){
// the file to be read.
FILE *islandsFile = fopen("islands.txt","r");
// temporary location to store the name read from the file.
char name[40];
// temporary pointer to an island which has been already read for linking.
island *previousIsland;
while(fscanf(islandsFile,"%s",name) != EOF){
// allocate …Run Code Online (Sandbox Code Playgroud) 我尝试从用户那里获取字符串输入。但它无法接收 arr[0][0] 处的输入。
关于程序: 在动态二维数组程序中,在该数组矩阵中搜索字符串并返回 true 或 false。
class SearchString{
public static void main(String[] args){
int n, m;
System.out.println("Enter the size of 2d array: ");
Scanner s = new Scanner(System.in);
n = s.nextInt();
m = s.nextInt();
String[][] arr = new String[n][m];
System.out.println("Enter the elements: ");
for(int i = 0; i < arr.length; i++){
for(int j = 0; j < arr[i].length; j++){
System.out.println("arr["+i+"] ["+j+"]"); arr[i][j] = s.nextLine();
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
Enter the size of 2d array:
2
2
Enter the …Run Code Online (Sandbox Code Playgroud) 假设您有一个Date对象,其中包含日/月和年值.
我想知道它是哪个日期.
我的意思是,就像3月5日那样是一年中的第65个.或者像1月15日是15日.
请不要joda时间.(未在当前项目中使用.)
我有这个示例代码:
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
int main(void){
printf("%li\n",sizeof(char));
char mytext[20];
read(1,mytext,3);
printf("%s",mytext);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
第一次运行:
koray@koray-VirtualBox:~$ ./a.out
1
pp
pp
koray@koray-VirtualBox:~$
Run Code Online (Sandbox Code Playgroud)
好吧,我认为这是所有预期的,因为p是ASCII中定义的1字节长字符,我正在读取3个字节.(2 p和换行符)在终端中,我再次看到2个字符.
现在让我们尝试一个2字节长的字符:
koray@koray-VirtualBox:~$ ./a.out
1
?
?
Run Code Online (Sandbox Code Playgroud)
我不明白的是,当我将字符'ğ'发送到mytext变量指向的内存时,16位被写入该区域.由于'ğ'是utf-8中的11000100:10011110,因此写入这些字节.
我的问题是,当打印回标准时,C(或者我应该说内核?)知道它应该读取2个字节并解释为1个字符而不是2个1字节字符?