Java name of day of week

Java name of day of week


Posted in : Java Posted on : August 18, 2011 at 6:13 PM Comments : [ 0 ]

In this section you will learn how to find the name of week.

Java name of day of week

In this section you will learn how to find the name of week.

Here I am giving a simple example which concern to HahsMap. The example given below is for finding the name of day of week from the corresponding number of days in a week i.e. if you are entering the number 1 then display a corresponding day 'Sunday'.

NameOfDay.java

import java.util.Map;
import java.util.HashMap;
import java.util.Scanner;

public class NameOfDay
{
public static void main(String arr[])
{
Map <Integer,String> map = new HashMap<Integer,String>();
map.put(1, "Sunday");
map.put(2, "Monday");
map.put(3, "Tuesday");
map.put(4, "Wednesday");
map.put(5, "Thursday");
map.put(6, "Friday");
map.put(7, "Saturday");
System.out.println("Enter a number from 1 - 7 to find the corresponding name of Day");
Scanner scan = new Scanner (System.in);
int i = scan.nextInt();
System.out.println(map.get(i));
}
}

Output :

When you will execute the above example you will get the output as :

Download Source Code

Go to Topic «PreviousHomeNext»

Your Comment:


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

 
Tutorial Topics