Question

Write a Java program that parse a date into the format of "m/d/y" that with month,...

Write a Java program that parse a date into the format of "m/d/y" that with month, day, and year all in single digits.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer:

import java.util.*;
public class Main
{
   public static void main(String[] args) {
       Scanner sc= new Scanner(System.in);
       String s1=sc.nextLine();
       StringTokenizer s=new StringTokenizer(s1,"/");
       int month,day,year;
       month=Integer.parseInt(s.nextToken());
       day=Integer.parseInt(s.nextToken());
       year=Integer.parseInt(s.nextToken());
      
   System.out.println(month);
   System.out.println(day);
   System.out.println(year);
  
   }
}


code:

output:

EXplanation:

We are taking string as an input.Inorder to extract month,year,date from the string we need to split the string at /.

so for that we need to stringTokenizer class,is used to split at /.we need to convert the date month and year values to int.So for that we need to use Integer.parseInt() method.

Add a comment
Know the answer?
Add Answer to:
Write a Java program that parse a date into the format of "m/d/y" that with month,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I need this in Java, please! The ISO 8601 Standard date format for Information Interchange indicates...

    I need this in Java, please! The ISO 8601 Standard date format for Information Interchange indicates that a date be written as such: yyyy-MM-dd (eg. 2012-07-02, 1999-12-05, 1998 -01-27 ) where yyyy represents the four digit year MM represents a two digit numerical month dd represents a two digit numerical day Chinese date format is specified as: yyyy-M-d Macedonean date format is specified as: d.M.yyyy where yyyy represents the four digit year M represents a one or two digit numerical...

  • Write a program that prompts the user to enter the date in mm/dd/yyyy format. The program...

    Write a program that prompts the user to enter the date in mm/dd/yyyy format. The program should use a single input statement to accept the date, storing each piece of the date into an appropriate variable. Demonstrate that the input was obtained correctly by outputting the month, day, and year to the screen. Sample output: Enter (date (mm/dd/yyyy): 02/08/2011 Month entered: 2 Day entered: 8 Year entered: 2011 Challenge: Although the user entered 02, C++ drops the 0 as insignificant...

  • using C programming Date Write a program that reads a month and a day in that...

    using C programming Date Write a program that reads a month and a day in that month and prints the date in format "month day". The input is two integers, one between 1 and 12 (inclusive) and one between 1 and 31 (inclusive) and the output is a single line in format "month day". For example, for input 2 10 the program will print "February 10th". The day will always have the ordinal indicator, e.g. 1st, 2nd, 3rd, 4th. Example...

  • 3. Using no date-specific Java libraries, write a program that computes the number of days between...

    3. Using no date-specific Java libraries, write a program that computes the number of days between any two dates (inclusive). You must take into account leap years. The rule for computing a leap year is as follows: If the year is divisible by 4 it is a Leap Year ... Unless the year is divisible by 100, then it is _not_ a Leap Year ... Unless the year is divisible by 400, then it _is_ a Leap Year. During a...

  • In Java You are to write a program that determines the day of the week for...

    In Java You are to write a program that determines the day of the week for New Year's Day in the year 3000. To do this, you must create your own date class (MyDate) and use the following interface and main program: /** Interface for Date objects to be used by the Year3000 driver program. @author Jon Sorenson */ public interface DateInterface { /** @return the day of the month (1-31) */ public int getDay(); /** @return the day of...

  • Language: Java The date June 10 1960 is special because when it is written in the...

    Language: Java The date June 10 1960 is special because when it is written in the form: month times day it will equal to the year (last two digits only). For example, 6 (for June) times 10 (day 10) equals 60 (the last two digits of year 1960). Write program to prompt user to enter month as an integer, day as an integer and a 2-digits integer for the year. No need to validate these input. Only test for being...

  • JAVA LANGUAGE create an empty Java file called Date build it to find any syntax errors...

    JAVA LANGUAGE create an empty Java file called Date build it to find any syntax errors and eliminate them identify each member of this class and write your answer in a comment There are four different types of class member: constant, instance variable, constructor, and method identify a method as class method if it is static /* * Java program: Date.java * * Define the class Date */ import java.time.LocalDateTime; public class Date { private static final int daysEachYear =...

  • Write a java application, Date, that reads an 8-digit integer value (indicating a date) from the...

    Write a java application, Date, that reads an 8-digit integer value (indicating a date) from the keyboard; the first two digits indicate the month, the second two digits represent the day and the last 4 digits represent the year. After calculating the month, the application will implement a switch statement to output the month. After displaying the date, the application will implement a nested if else statement to output the appropriate century. i.e Prev17th century, 18th century, 19th century, 20th...

  • In Java, write a program that asks the user for the name of a file. The...

    In Java, write a program that asks the user for the name of a file. The program should read all the numbers from the given file and display the total and average of all numbers in the following format (three decimal digits): Total: nnnnn.nnn Average: nnnnn.nnn Class name: FileTotalAndAverage

  • C Program Question 1: Write a program that reads a date from the keyboard and tests...

    C Program Question 1: Write a program that reads a date from the keyboard and tests whether it contains a valid date. Display the date and a message that indicates whether it is valid. If it is not valid, also display a message explaining why it is not valid. The input date will have the format: mm/dd/yyyy Note that there is no space in the above format. A date in this format must be entered in one line. A valid...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT