Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/Helper.java
Original file line number Diff line number Diff line change
@@ -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();

}
}
31 changes: 5 additions & 26 deletions src/PracticeGitIgnore.java
Original file line number Diff line number Diff line change
@@ -1,29 +1,8 @@
import java.util.Scanner;

//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
// click the <icon src="AllIcons.Actions.Execute"/> 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();
}

}
}