diff --git a/src/Helper.java b/src/Helper.java new file mode 100644 index 0000000..aba536c --- /dev/null +++ b/src/Helper.java @@ -0,0 +1,21 @@ +import java.util.Scanner; +public class Helper { + private static final Scanner scanner = new Scanner(System.in); + + public static String getInput(String prompt) { + System.out.print(prompt); + + return scanner.nextLine(); + } + + public static int getIntInput(String prompt) { + System.out.print(prompt); + + return scanner.nextInt(); + } + public static void closeScanner() { + + scanner.close(); + + } +} \ No newline at end of file diff --git a/src/PracticeGitIgnore.java b/src/PracticeGitIgnore.java index a3359b4..46a8a86 100644 --- a/src/PracticeGitIgnore.java +++ b/src/PracticeGitIgnore.java @@ -1,29 +1,8 @@ -import java.util.Scanner; - -//TIP To Run code, press or -// click the icon in the gutter. public class PracticeGitIgnore { public static void main(String[] args) { - - // Create a scanner object to read input - Scanner scanner = new Scanner(System.in); - - // Prompt the user to enter the first string - System.out.print("Enter the first string: "); - String s1 = scanner.nextLine(); - - // Prompt the user to enter the second string - System.out.print("Enter the second string: "); - String s2 = scanner.nextLine(); - - // Concatenate the two strings - String result = s1 + s2; - - // Print the concatenated result - System.out.println("Concatenated result: " + result); - - // Close the scanner - scanner.close(); + String name = Helper.getInput("Enter your name: "); + int age = Helper.getIntInput("Enter your age: "); + System.out.println("Hello, " + name + "! You are " + age + " years old."); + Helper.closeScanner(); } - -} +} \ No newline at end of file