String strFirst = System.in.toString(); //strFirst想得到键入的字符串,如何实现?
public class dh01_01
{
public static void main(String args[])
{
System.out.println("please input the first:");
String strFirst = System.in.toString();
System.out.println("the first string is:" + strFirst);
}
}

解决方案 »

  1.   

    import java.util.Scanner;public class dh01_01
    public static void main(String[] args) {
    Scanner s = new Scanner(System.in);
    String strFirst = s.next();
    System.out.println(strFirst);
    }
    }
      

  2.   

    import java.util.Scanner;public class TestScanner { /**
     * @param args
     */
    public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    System.out.println("input : (exit to out)");

    String line = "";

    while (!"exit".equals((line=scanner.nextLine()))) {
    System.out.println("line : " + line);
    System.out.println();
    }
    }
    }
    可以连续输入,只要不是exit
      

  3.   

    谢谢提点!demo已写好了。import java.util.Scanner;public class dh01_01
    {
    public static void main(String args[])
    {
    Scanner scan = new Scanner(System.in); System.out.println("please input the first:");
    String strFirst = scan.next();
    System.out.println("the first string is:" + strFirst); System.out.println("please input the second:");
    String strSecond = scan.next();
    System.out.println("the second string is:" + strSecond);

    System.out.println("please input the third:");
    String strThird = scan.next();
    System.out.println("the third string is:" + strThird); int iFirst = Integer.parseInt(strFirst);
    int iSecond = Integer.parseInt(strSecond);
    int iFinal = 0;
    boolean bGet = false;

    if (0 == strThird.compareToIgnoreCase("+"))
    {
    iFinal = iFirst + iSecond;
    bGet = true;
    }
    else if (0 == strThird.compareToIgnoreCase("-"))
    {
    iFinal = iFirst - iSecond;
    bGet = true;
    }
    else if (0 == strThird.compareToIgnoreCase("-"))
    {
    iFinal = iFirst - iSecond;
    bGet = true;
    }
    else if (0 == strThird.compareToIgnoreCase("*"))
    {
    iFinal = iFirst * iSecond;
    bGet = true;
    }
    else if (0 == strThird.compareToIgnoreCase("/"))
    {
    iFinal = iFirst / iSecond;
    bGet = true;
    }

    if (bGet)
    {
    System.out.println("the final value is:" + iFinal);
    }
    else
    {
    System.out.println("something is wrong");
    }
    }
    }
      

  4.   

    package test;import java.util.Scanner;public class Test {
    public static void main(String[] args) {
          Scanner scanner = new Scanner(System.in);
            System.out.println("input : (exit to out)");
            String line = "";
            while (!"exit".equals((line=scanner.nextLine()))) {//换行的时候
                System.out.println("line : " + line);
                System.out.println();
            } }
    }
      

  5.   

    import java.util.*;
    public class dh01_01
    {
        public static void main(String args[])
        {
         Scanner in=new Scanner(System.in);
            System.out.println("please input the first:");        String strFirst = in.nextLine();
            System.out.println("the first string is:" + strFirst);
        }
    }
      

  6.   

    int iFirst = scan.nextInt();
    int iSecond = scan.nextInt();