给段代码你吧,看来你是初学者 import java.io.*; public class inputor{ public static void main (String args[]) { BufferedReader input =new BufferedReader(new InputStreamReader(System.in)); String s=new String(); try{ System.out.println("Please input:"); s=input.readLine(); }catch(IOException e){ e.printStackTrace(); } System.out.println("The words inputed is:"+s); } }
给你一个最新的jdk1.5.0的用法 import java.util.*; public class scanner { public static void main(String args[]) { int i[]=new int[5]; Scanner in=new Scanner(System.in); for(int j=0;j<i.length;j++) {i[j]=in.nextInt(); //想输入char就用in.nextChar(); } for(int j=0;j<i.length;j++) System.out.print(i[j]+" "); } }
使用Scanner是调用API进行格式化输入 包含在ava.util.*中
看看这个 public class Example { public static void main(String[] args) { for(int i=0;i<args.length;i++) System.out.println(args[i]); } } 编译时 javac Example.java java Example input your string//input your string 是你要输入的字符;
jdk1.5 Scanner sc = new Scanner(System.in); int i = sc.nextInt(); jdk 1.4看看IO BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String s=in.readLine(); System.out.println("Input value is: "+s); int i = Integer.parseInt(s);//转换成int型
都不明白现在的人是怎么想的---初学者
import java.io.*;
public class inputor{
public static void main (String args[])
{
BufferedReader input =new BufferedReader(new InputStreamReader(System.in));
String s=new String();
try{
System.out.println("Please input:");
s=input.readLine();
}catch(IOException e){
e.printStackTrace();
}
System.out.println("The words inputed is:"+s);
}
}
import java.util.*;
public class scanner
{
public static void main(String args[])
{
int i[]=new int[5];
Scanner in=new Scanner(System.in);
for(int j=0;j<i.length;j++)
{i[j]=in.nextInt(); //想输入char就用in.nextChar();
}
for(int j=0;j<i.length;j++)
System.out.print(i[j]+" ");
}
}
包含在ava.util.*中
public class Example
{
public static void main(String[] args)
{
for(int i=0;i<args.length;i++)
System.out.println(args[i]);
}
}
编译时 javac Example.java
java Example input your string//input your string 是你要输入的字符;
Scanner sc = new Scanner(System.in);
int i = sc.nextInt();
jdk 1.4看看IO
BufferedReader br =
new BufferedReader(new InputStreamReader(System.in));
String s=in.readLine();
System.out.println("Input value is: "+s);
int i = Integer.parseInt(s);//转换成int型
String s=" ";
int i=0;
double d=0;
try{
BufferedReader in =new BufferedReader(new InputStreamReader(System.in));
System.out.println("请输入一个整数:");
s=in.readLine();
i=Integer.parseInt(s);
System.out.println("请输入一个实数:");
s=in.readLine();
d=Double.parseDouble(s);
}catch(IOException e){}
这就是输入。
import java.io.*;
import java.lang.*;
public class CalculateCj {
String studentNo="";
float psf=0;
float qzf=0;
float qmf=0;
float qmbs=0;
private int count=0;
CalculateCj[] ClassZs;
CalculateCj(){
}
CalculateCj(int n)
{ count=n;
ClassZs=new CalculateCj[n];
for(int i=0;i<n;i++){
ClassZs[i]=new CalculateCj();
}}
public void setPsf(int i,float psf1){
ClassZs[i].psf=psf1;
}
public void setQzf(int i,float qzf1){
ClassZs[i].qzf=qzf1;
}
public void setQmf(int i,float qmf1){
ClassZs[i].qmf=qmf1;
}
public void setQmbs(int i,float qmbs1){
ClassZs[i].qmbs=qmbs1;
}public float getZF(int i){
float score;
score=0;
score+=0.10*ClassZs[i].psf+0.25*ClassZs[i].qzf+0.15*ClassZs[i].qmf+0.50*ClassZs[i].qmbs;
return score;
}
public void printDK(){
try {
for (int i=0;i<count;i++){
String result="";
result="学号:"+ClassZs[i].studentNo+"平时分:"+ClassZs[i].psf;
result+="期中:"+ClassZs[i].qzf+"期末上机:"+ClassZs[i].qmf+"期末笔试:"+ClassZs[i].qmbs;
System.out.println(result);
}
}
catch (Exception ex) {
}
}public void inputAllData(){
for(int i=0;i<count;i++){
inputData(i);
}
}
public void printFilterCJGood(){
for(int i=0;i<count;i++){
if (getZF(i)>=90)
System.out.println("学号:"+ClassZs[i].studentNo+"总评成绩:"+getZF(i));
}
}public void printFilterCJBad(){
for(int i=0;i<count;i++){
if (getZF(i)<60)
System.out.println("学号:"+ClassZs[i].studentNo+"总评成绩:"+getZF(i));
}
}public void inputData(int i){
try {
BufferedReader streami = new BufferedReader(
new InputStreamReader(System.in));
String studentInfo;
studentInfo="";
System.out.print("请输入学号:");
studentInfo=streami.readLine();
ClassZs[i].studentNo=studentInfo;
System.out.print("请输入平时分:");
studentInfo=streami.readLine();
ClassZs[i].psf=Float.parseFloat(studentInfo);
System.out.print("请输入期中分:");
studentInfo=streami.readLine();
ClassZs[i].qzf=Float.parseFloat(studentInfo);
System.out.print("请输入期末上机分:");
studentInfo=streami.readLine();
ClassZs[i].qmf=Float.parseFloat(studentInfo);
System.out.print("请输入期末笔试分:");
studentInfo=streami.readLine();
ClassZs[i].qmbs=Float.parseFloat(studentInfo); }
catch (Exception ex) {System.out.print(ex.toString());
}
}
public static void main(String []args){
CalculateCj myClass=new CalculateCj(8);
myClass.inputAllData();
System.out.println("90分及以上学生的情况:");
myClass.printFilterCJGood();
System.out.println("不及格的学生的情况:");
myClass.printFilterCJBad();
System.out.println("所有学生的情况:");
myClass.printDK();
}
}
public static void main(String[] args) throws IOException {
BufferedReader reader =new BufferedReader(new InputStreamReader(System.in));
String s = reader.readLine();
System.out.println(s);
}
}