Java:循环输入字符串,输入0终止

package ch01;

 

import java.util.Scanner;

 

public class string1 

{

public static void main(String[] args)

{

String s=" ";

//String s1="0";

System.out.print("请输入一串字符:");

while(!s.equals("0"))

{

 

try

{

Scanner reader=new Scanner(System.in);

s=reader.next();

}

catch(Exception e)

{

e.printStackTrace();

}

if(s.equals("0"))

{

System.out.println("输入结束!");

    System.exit(0);

}

System.out.println("您输入的字符串是:"+s);

 

System.out.print("请输入一串字符:");

}

}

}

 

posted @ 2019-06-28 16:04  bobo哥  阅读(5427)  评论(0编辑  收藏  举报