Last active
April 23, 2021 18:22
-
-
Save cassiusvm/9879f7021812bd25fc5cbf93a0988d03 to your computer and use it in GitHub Desktop.
Revisions
-
cassiusvm revised this gist
Sep 16, 2018 . 1 changed file with 40 additions and 20 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,45 +1,65 @@ import java.io.Console; import java.util.Scanner; public class App { public void perform() { firstScanner(); secondScanner(); } public void firstScanner() { String str = ""; Console con = System.console(); if (con != null) { try (Scanner sc = new Scanner(con.reader())) { System.out.println("Enter a string: "); if (sc.hasNext()) { str = sc.next(); sc.nextLine(); } System.out.println("str = " + str); } catch (Exception e) { System.out.println("Exception message: " + e.getMessage()); } } else { System.out.println("System console not available"); } } public void secondScanner() { int num = 0; Console con = System.console(); if (con != null) { try (Scanner sc = new Scanner(con.reader())) { System.out.println("Enter a number: "); if (sc.hasNextInt()) { num = sc.nextInt(); sc.nextLine(); } System.out.println("num = " + num); } catch (Exception e) { System.out.println("Exception message: " + e.getMessage()); } } else { System.out.println("System console not available"); } } public static void main(String[] args) { -
cassiusvm revised this gist
Sep 16, 2018 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -36,6 +36,7 @@ public class App { if (sc.hasNextInt()) { num = sc.nextInt(); sc.nextLine(); } System.out.println("num = " + num); -
cassiusvm created this gist
Sep 16, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,51 @@ import java.util.Scanner; public class App { public void perform() { try (Scanner sc = new Scanner(System.in)) { firstScanner(sc); secondScanner(sc); } catch (Exception e) { System.out.println("Exception message: " + e.getMessage()); } } public void firstScanner(Scanner sc) { String str = ""; System.out.println("Enter a string: "); if (sc.hasNext()) { str = sc.next(); sc.nextLine(); } System.out.println("str = " + str); } public void secondScanner(Scanner sc) { int num = 0; System.out.println("Enter a number: "); if (sc.hasNextInt()) { num = sc.nextInt(); } System.out.println("num = " + num); } public static void main(String[] args) { App app = new App(); app.perform(); System.exit(0); } }