Code Monkey home page Code Monkey logo

ex-03-java's Introduction

Ex-03:

Java program to find the number of days in a month

AIM:

To write a java program to find the number of days in a month

ALGORITHM:

  1. Import required packages.
  2. Declare main method with the signature "public static void main(String[] args)".
  3. Get the month input from user.
  4. Use switch method to find the number of days for the given month input.
  5. Display the output.

PROGRAM:

import java.util.Scanner;
public class Ex3
{
    public static void main(String[] args)
    {
        Scanner in = new Scanner(System.in);
        System.out.println("Enter a month: ");
        String str = in.nextLine();
        System.out.println("The number of days in "+str+": ");
        switch(str)
        {
            case "January":
                System.out.print("31");
                break;
            case "February":
                System.out.print("28");
                break;
            case "March":
                System.out.print("31");
                break;
            case "April":
                System.out.print("30");
                break;
            case "May":
                System.out.print("31");
                break;
            case "June":
                System.out.print("30");
                break;
            case "July":
                System.out.print("31");
                break;
            case "August":
                System.out.print("31");
                break;
            case "September":
                System.out.print("30");
                break;
            case "October":
                System.out.print("31");
                break;
            case "November":
                System.out.print("30");
                break;
            case "December":
                System.out.print("31");
                break;
        }
    }
}

OUTPUT:

image

RESULT:

To write a java program to find the number of days in a month was successfully done.

ex-03-java's People

Contributors

keerthikanagarajan avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.