Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Vasanth S
Vasanth S

Posted on

     

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 modeExit 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 modeExit 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 modeExit 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 modeExit fullscreen mode

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

I am Vasanth from the department of Information Technology, currently pursing my UG degree. I have been learning the flutter app development and also a Java programing language.
  • Pronouns
    He
  • Joined

More fromVasanth S

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp