Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. package com.lotus.exam;
  2.  
  3. import java.text.ParseException;
  4. import java.text.SimpleDateFormat;
  5. import java.util.Calendar;
  6. import java.util.Date;
  7. import java.util.Scanner;
  8.  
  9. public class Main {
  10.  
  11. public Main() {
  12. // TODO Auto-generated constructor stub
  13. }
  14.  
  15. public static void main(String[] args) {
  16. //ageFinder();
  17. wordFinder();
  18. }
  19.  
  20. public static void ageFinder(){
  21. System.out.println("Java 7: Enter Bday format mm/dd/yyyy");
  22. SimpleDateFormat f = new SimpleDateFormat("MM/dd/yyyy");
  23. Scanner s = new Scanner( System.in );
  24. String dateLine = s.nextLine();
  25. Date d = new Date();
  26. try
  27. {
  28. d = f.parse( dateLine );
  29. }
  30. catch( ParseException e )
  31. {
  32. System.out.println("please enter a valid date in format mm/dd/yyyy");
  33. }
  34. Calendar c = Calendar.getInstance();
  35. c.setTimeInMillis( System.currentTimeMillis() - d.getTime() );
  36. System.out.print("Your age is : ");
  37. if(c.get( Calendar.YEAR ) - 1970 >= 0){
  38. System.out.println(c.get( Calendar.YEAR ) - 1970 );
  39. } else {
  40. System.out.println(0);
  41. }
  42. }
  43.  
  44. public static void wordFinder(){
  45. System.out.println("Your word finder input please:");
  46. Scanner s = new Scanner( System.in );
  47. String inputWord = s.nextLine();
  48. s.close();
  49. System.out.println(inputWord);
  50. Dictionary dict = Dictionary.getInstance();
  51. for(String word : dict){
  52. if(inputWord.matches("(.*)".concat(word).concat("(.*)"))){
  53. inputWord = inputWord.replace(word, word.concat(" "));
  54. }
  55. }
  56. System.out.println("Your expected output will be:");
  57. System.out.println(inputWord);
  58. }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement