java中,怎样实现键盘输入?
5个回答
展开全部
java---由键盘输入数据,字符串-BufferedReader的用法
范例一:有键盘输入一串字符串,
import java.io.*;
public class bufferedreader{
public static void main(String args[]) throws IOException
{
String mystring;
BufferedReader buf=new BufferedReader(new InputStreamReader(System.in));
System.out.println("input a string");
mystring=buf.readLine();
System.out.println("string="+mystring);
}
}
范例2:有键盘输入数据:
import java.io.*;
public class bufferedreader
{
public static void main(String args[]) throws IOException
{
String mystring;
int myint;
BufferedReader buf=new BufferedReader(new InputStreamReader(System.in));
System.out.println("input an integer");
mystring=buf.readLine();
myint=Integer.parseInt(mystring);
System.out.println("the integer is="+myint);
}
}
范例3:由键盘输入两个整数,并且求和:
import java.io.*;
public class bufferedreader
{
public static void main(String args[]) throws IOException
{
String mystring1,mystring2;
int myint1,myint2;
BufferedReader buf=new BufferedReader(new InputStreamReader(System.in));
System.out.println("please input the first number");
mystring1=buf.readLine();
myint1=Integer.parseInt(mystring1);
System.out.println("please input the second number");
mystring2=buf.readLine();
myint2=Integer.parseInt(mystring2);
System.out.println(myint1+"+"+myint2+"="+(myint1+myint2));
}
}
范例一:有键盘输入一串字符串,
import java.io.*;
public class bufferedreader{
public static void main(String args[]) throws IOException
{
String mystring;
BufferedReader buf=new BufferedReader(new InputStreamReader(System.in));
System.out.println("input a string");
mystring=buf.readLine();
System.out.println("string="+mystring);
}
}
范例2:有键盘输入数据:
import java.io.*;
public class bufferedreader
{
public static void main(String args[]) throws IOException
{
String mystring;
int myint;
BufferedReader buf=new BufferedReader(new InputStreamReader(System.in));
System.out.println("input an integer");
mystring=buf.readLine();
myint=Integer.parseInt(mystring);
System.out.println("the integer is="+myint);
}
}
范例3:由键盘输入两个整数,并且求和:
import java.io.*;
public class bufferedreader
{
public static void main(String args[]) throws IOException
{
String mystring1,mystring2;
int myint1,myint2;
BufferedReader buf=new BufferedReader(new InputStreamReader(System.in));
System.out.println("please input the first number");
mystring1=buf.readLine();
myint1=Integer.parseInt(mystring1);
System.out.println("please input the second number");
mystring2=buf.readLine();
myint2=Integer.parseInt(mystring2);
System.out.println(myint1+"+"+myint2+"="+(myint1+myint2));
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
BufferedReader bw = new BufferedReader(new InputStreamReader(System.in));
String str=bw.ReadLine();
String str=bw.ReadLine();
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
import java.util.*;
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
参考资料: http://www.javabiz.cn
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
我去,这个youngsunshine回答跟上老师他老师了,不采纳这个为答案真是浪费了,很不错,方法都全了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
System.in.prinln();
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询