getchar 或 system可以解决点击exe输出完就关闭的问题
getchar();getchar();
跟
system("pause");
一个意思
用下面这个要在请求头中加上
#include <stdlib.h>
即
#include <stdio.h>
#include <stdlib.h>
int main()
{
printf("hello\n");
system("pause");
}
#include <stdio.h>
int main()
{
printf("hello\n");
getchar();getchar();
}
输入scanf(’%s’,t) 数字是%d
char t[10];//必须带[] 10表示长度
scanf("%s",t); //把每一个数读到变量t中
printf("%s ",t);
getchar();getchar();
想输入空格
scanf("%s%s%s",a,b,c);
printf("%s %s %s",a,b,c);
java
import java.util.Scanner;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入你的姓名:");
String name = sc.nextLine();
System.out.println("请输入你的年龄:");
int age = sc.nextInt();
System.out.println("请输入你的工资:");
float salary = sc.nextFloat();
System.out.println("你的信息如下:");
System.out.println("姓名:"+name+"\n"+"年龄:"+age+"\n"+"工资:"+salary);
}
该对象的next()方法和nextLine()方法的区别:
在java中,next()方法是不接收空格的,在接收到有效数据前,所有的空格或者tab键等输入被忽略,若有有效数据,则遇到这些键退出。nextLine()可以接收空格或者tab键,其输入应该以enter键结束。