Click here to watch in Youtube :
https://www.youtube.com/watch?v=d_hl_GdDH5c&list=UUhwKlOVR041tngjerWxVccw
ScannerDemo.java
Output
https://www.youtube.com/watch?v=d_hl_GdDH5c&list=UUhwKlOVR041tngjerWxVccw
ScannerDemo.java
import java.util.ArrayList; import java.util.Scanner; public class ScannerDemo { public static void main(String[] args) { Scanner scanner = null; try { ArrayList<String> listOfNames = new ArrayList<String>(); scanner = new Scanner(System.in); System.out.print("Enter the name: "); while (scanner.hasNextLine()) { String name = scanner.nextLine(); if (name.equalsIgnoreCase("quit")) { break; } listOfNames.add(name); System.out.print("Enter the name: "); } System.out.println("listOfNames = "+listOfNames); } finally { if (scanner != null) { scanner.close(); } } } }
Enter the name: peter Enter the name: dave Enter the name: ram Enter the name: quit listOfNames = [peter, dave, ram]
https://sites.google.com/site/ramj2eev1/home/javabasics/JavaIODemo_Scanner_while%20loop_App.zip?attredirects=0&d=1
Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/JavaIODemo_Scanner_while%20loop_App
Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/16638d65b46bec1088dab744ba69a31424c4a14f/BasicJava/JavaIODemo_Scanner_while%20loop_App/?at=master
See also:
No comments:
Post a Comment