DEV Community

Vasanth S
Vasanth S

Posted on

3 1

Practice Programs using Functions

Today's Practice Programs are
These programs are Practice using a functions.
1.Age Category
program :
import java.util.Scanner;

public class Category {
static String isage(int num)
{
if(num>=50){
return "Your age is above 50";
} else if (num>=40 && num<=50) {
return "Your age is between 40 to 50";
}
else
return "Your age is less than 40";
}
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
System.out.println("Enter the age :");
int age=in.nextInt();
System.out.println(isage(age));

}
Enter fullscreen mode Exit fullscreen mode

}

**
2.Adding two numbers**
program :
import java.util.Scanner;

public class big_two {
static boolean isgreater(int c, int d){
if(c>d){
return true;
}
return false;

}
public static void main(String[] args) {
    Scanner input=new Scanner(System.in);
    System.out.println("Enter two numbers :");
    int a=input.nextInt();
    int b=input.nextInt();
    if(isgreater(a,b)){
        System.out.println(a+" is greater");
    }
    else{
        System.out.println(b+" is greater");
    }

}
Enter fullscreen mode Exit fullscreen mode

}

**3.Vowel or not
**program :
import java.util.Scanner;
public class vowel {
static boolean vowels(char b){
String s="aeiouAEIOU";
for (int i=0;i<s.length();i++) {
if (b == (s.charAt(i))) {
return true;
}

    }
    return false;
}
public static void main(String[] args) {
    Scanner input = new Scanner(System.in);
    System.out.println("Enter the Character : ");
    char a=input.next().charAt(0);
    if(vowels(a)){
        System.out.println(a+" is vowel");
    }
    else
        System.out.println(a+" is not a vowel");
}
Enter fullscreen mode Exit fullscreen mode

}

4.Good Morning message
program :
import java.util.Scanner;

public class goodM {
static String isgood(int a){
if(a%3==0 && a%4==0){
return "Good Morning";
} else if (a%4==0) {
return "Good afternoon";
} else if (a%3==0) {
return "Good Evening";
}
else
return "Good Night";
}
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
System.out.println("Enter the number :");
int num=in.nextInt();
System.out.println(isgood(num));
}
}

**5.Season
**program :
import java.util.Scanner;

public class season {
static String ismonth(int m){
if(m>=3 && m<=5){
return "Spring Season";
} else if (m>=6 && m<=8) {
return "Summer Season";
} else if (m>=9 && m<=11) {
return "Autumn Season";
} else if (m==12 && m>=1 && m<=2) {
return "Winter Season";
}
else{
return "Invalid input";
}
}
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
System.out.println("Enter a month : ");
int month=in.nextInt();
System.out.println(ismonth(month));

    }
}
Enter fullscreen mode Exit fullscreen mode

Speedy emails, satisfied customers

Postmark Image

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more