Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.lotus.exam;
- import java.text.ParseException;
- import java.text.SimpleDateFormat;
- import java.util.Calendar;
- import java.util.Date;
- import java.util.Scanner;
- public class Main {
- public Main() {
- // TODO Auto-generated constructor stub
- }
- public static void main(String[] args) {
- //ageFinder();
- wordFinder();
- }
- public static void ageFinder(){
- System.out.println("Java 7: Enter Bday format mm/dd/yyyy");
- SimpleDateFormat f = new SimpleDateFormat("MM/dd/yyyy");
- Scanner s = new Scanner( System.in );
- String dateLine = s.nextLine();
- Date d = new Date();
- try
- {
- d = f.parse( dateLine );
- }
- catch( ParseException e )
- {
- System.out.println("please enter a valid date in format mm/dd/yyyy");
- }
- Calendar c = Calendar.getInstance();
- c.setTimeInMillis( System.currentTimeMillis() - d.getTime() );
- System.out.print("Your age is : ");
- if(c.get( Calendar.YEAR ) - 1970 >= 0){
- System.out.println(c.get( Calendar.YEAR ) - 1970 );
- } else {
- System.out.println(0);
- }
- }
- public static void wordFinder(){
- System.out.println("Your word finder input please:");
- Scanner s = new Scanner( System.in );
- String inputWord = s.nextLine();
- s.close();
- System.out.println(inputWord);
- Dictionary dict = Dictionary.getInstance();
- for(String word : dict){
- if(inputWord.matches("(.*)".concat(word).concat("(.*)"))){
- inputWord = inputWord.replace(word, word.concat(" "));
- }
- }
- System.out.println("Your expected output will be:");
- System.out.println(inputWord);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement