Advertisement
CharlesF

InputReader

Feb 20th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class InputReader {
  4.  
  5. String str1, str2;
  6. Scanner scanner;
  7.  
  8. public static void main(String[] args) {
  9. // TODO Auto-generated method stub
  10. InputReader inreader = new InputReader();
  11. inreader.printInput();// calls printInput method
  12. inreader.matchEcho(); //calls matchEcho method
  13. inreader.printProduct(); //calls printProduct method
  14. }
  15. void printInput() {
  16. System.out.println("Please enter a string");
  17. scanner = new Scanner (System.in);
  18. str1 = scanner.next();
  19. System.out.println("You entered:" + str1);
  20. }
  21.  
  22. void matchEcho() {
  23. System.out.println("Please enter a string:");
  24. scanner = new Scanner(System.in);
  25. str2 = scanner.next();
  26.  
  27. if (str2.equals("echo")) {
  28. System.out.println("Match!");
  29. }
  30. else
  31. System.out.println("Not a match");
  32. }
  33.  
  34. void printProduct() {
  35. System.out.println("Please enter first int");
  36. scanner = new Scanner(System.in);
  37. int int1 = scanner.nextInt();
  38. System.out.println("Please enter second int");
  39. int int2 = scanner.nextInt();
  40. int product = int1*int2;
  41. System.out.println("The product is:" + product);
  42. }
  43.  
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement