Scanner class Methods in Java

Coding is Fun

Write a program for fun in Java.

Here, I am writing this program to show my love for tea. You need to find fun ways to code. Sometimes, we get quite serious in life and forget to enjoy the tiny moments.This post is just for fun.

coding memes program in java

In the above program,

I created a class "Mood". In main method Scanner object is used to take input from user.It asks user to write his current mood. User 's mood can be happy ,sad, tired or  off. Then the static method "takeTea()" is invoked with mood as argument.

The "takeTea(String mood)" method uses if statement to compare mood with different feelings entered by user. Logical OR (||) operator is used to test various conditions at once.

The if block prints the statement "Have some tea!" and else prints "Shut up and start coding!!".

Output:

Lets see what happens when two feelings "happy" and "sad" are entered.

coding is fun in java

coding is fun in java

I hope you enjoyed this post. Happy Coding!


Comments