2013年9月17日星期二

java how circulating enter numbers, then press Enter to know out of the loop ?

java how circulating enter numbers, then press Enter to know out of the loop ?
------ Solution ---------------------------------------- ----
if you want the command line , then press Enter to achieve very good out of the loop on

But you can consider the output a non-numeric , or fixed a bye or exit out of the loop the string and then
------ Solution --------------- -----------------------------
Scanner

while (scanner.hasNextInt ()) {...}
enter a non- integer out of the loop .
Other hasNextXXX method has the same effect
------ Solution -------------------------- ------------------
this is a very simple example , the output bye ( not case sensitive ) to exit

import java.util.Scanner;


public class Test001 {
    public static void main(String[] args) {
        System.out.println("↑ ↓ ← →");
        Scanner scanner=new Scanner(System.in);
        System.out.print("请输入数字");
        String input="";
        while(!input.equalsIgnoreCase("bye")){
             input=scanner.next();
        }
        System.out.println("您已经退出");

    }
}


------ Solution ------------------------------------- -------
enter a carriage return after the out of the loop , that you read one line .

readLine line after parsing the contents of this line .
------ For reference only -------------------------------------- -

amount . . I am a novice with java doing acm. . This problem is certainly not as engaging as you say .
suddenly found java input and output so depressed
------ For reference only -------------------------- -------------

does not seem to ah.
------ For reference only -------------------------------------- -
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNextInt()) {
            System.out.println(scanner.nextInt());
        }
        System.out.println("Exit");

1
1
2
2
3
3
4
4
5
5
a
Exit
odd lines are input, the even lines are output. Enter a time out of the loop.
------ For reference only -------------------------------------- -

amount I want is to press enter to come out . .
this I will . .
------ For reference only -------------------------------------- -
press Enter description in the second out of the loop . .
------ For reference only -------------------------------------- -

then I ask you, press enter to come out , then how can you achieve the cycle input ?

finished because each input to be used for the transport as determined at the end, jump if you press Enter , you can only achieve the input line ,

you want to enter only one line it ?


------ For reference only ---------------------------------- -----
seek advice with ah, want to enter a variable length array of numbers , and then enter the end input , how to get ?

没有评论:

发表评论