java的输入那么麻烦?

hl0oo 2010-03-23 10:18:09
我是初学者,我不知道为什么,我实在捉摸不透,
我想在控制台输入一个整型数。再赋给一个变量,请问要怎么做,
我对java一窍不通。
...全文
314 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
tdgwj 2010-03-24
  • 打赏
  • 举报
回复
字符串建议用1楼 Scanner不支持空格
hl0oo 2010-03-24
  • 打赏
  • 举报
回复
多谢了。
试了二楼的代码,行
sirtener 2010-03-24
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 justchenjie 的回复:]
import java.util.*;
public class Test
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);//建立一个扫描
System.out.println("请输入一个数:");
int c=sc.nextInt();//从中读取你输入的整数,当然也可以是……
[/Quote]
就是这种方法
北狐狸 2010-03-24
  • 打赏
  • 举报
回复
import java.util.*;
public class Test1
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);//建立一个扫描
System.out.println("请输入一个数:");
try{
int c=sc.nextInt();//从中读取你输入的整数,当然也可以是字符窜什么的
System.out.println(c);
} catch (InputMismatchException e)
{
System.out.println("InputMismatchException");
}

}
}
canoe982 2010-03-24
  • 打赏
  • 举报
回复
Scanner有不支持空格的方法,似乎也有支持空格的。
tdgwj 2010-03-24
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 taozhaocailiu 的回复:]

public class PrintTest {
public static void main(String arg[]) throws IOException {
char[] cbuf = new char[1024];
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.……
[/Quote]、
字符数组好像麽用到。。
重返春季 2010-03-24
  • 打赏
  • 举报
回复
public class PrintTest {
public static void main(String arg[]) throws IOException {
char[] cbuf = new char[1024];
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("请输入数字:");
System.out.println(br.readLine());
}
}
VirusFu 2010-03-23
  • 打赏
  • 举报
回复
楼上正解
justchenjie 2010-03-23
  • 打赏
  • 举报
回复
import java.util.*;
public class Test
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);//建立一个扫描
System.out.println("请输入一个数:");
int c=sc.nextInt();//从中读取你输入的整数,当然也可以是字符窜什么的
System.out.println(c);
}
}

这个应该容易接受
wwwtyb 2010-03-23
  • 打赏
  • 举报
回复
public class Test {
public static void main(String arg[]) throws IOException {
char[] cbuf = new char[1024];
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter characters");
// read characters
System.out.println(br.readLine());
}
}

62,620

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧