Wednesday 22 April 2020

GENERATING RANDOM NUMBER TO DISPLAY RANDOM MONTHS USING JAVA LANGUAGE

Q-34- Write a java program that randomly generates an integer between 1 and 12 and displays the English month name January, February… December for the number 1, 2… 12, accordingly.

INPUT :
public class NCM {

public static void main(String[] args) {
int num;
num= (int)(Math.random()*(12-1+1)+1);
if(num==1)
{
System.out.println("This Is January.");
}
else if(num==2)
{
System.out.println("This Is February.");
}
else if(num==3)
{
System.out.println("This Is March.");
}

else if(num==4)
{
System.out.println("This Is April.");
}
else if(num==5)
{
System.out.println("This Is May.");
}
else if(num==6)
{
System.out.println("This Is June.");
}
else if(num==7)
{
System.out.println("This Is July.");
}
else if(num==8)
{
System.out.println("This Is August.");
}
else if(num==9)
{
System.out.println("This Is September.");
}
else if(num==10)
{
System.out.println("This Is October.");
}
else if(num==11)
{
System.out.println("This Is November.");
}
else if(num==12)
{
System.out.println("This Is December.");
}

}


}

OUTPUT :
This Is June.

No comments:

Post a Comment