0% found this document useful (0 votes)
26 views47 pages

Java Programming Project Certificate

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views47 pages

Java Programming Project Certificate

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

NATIONAL ACADEMY SCHOOL

RAMANATHAPURAM
CERTIFICATE

This is to Certify that this project is the original work done by

________________________________________________________

__

Index No _________________________ in

______________________

during the academic year ___________________________

Signature of the Teacher In-charge

PRINCIPAL

Date:

Place:

School Seal Signature of the External

Examiner
NATIONAL ACADEMY SCHOOL,
RAMANATHAPURAM
ACKNOWLEDGEMENT
I hereby acknowledge that I have worked on the topic
________________________________ referring various
sources to prepare the project under the guidance of
Mr./Ms___________________________ teacher during the
academic year _____________.

I would like to thank my subject teacher for the guidance


given to me during the project work. I would also like to thank
my class teacher, parents and friends for their help and
encouragement.

I extend my heartfelt gratitude to the Principal for timely


advice and guidance.

Name: Signature
Index no: Date:
TABLE OF CONTENTS
Page
[Link] Date PROGRAM no Sign
1. Check whether the given number is odd or even
2. Find the factorial of the given number

3. Find the area and perimeter of the circle

4. To print the days of the week using switch case.


5. To print inverted half pyramid using *
6. To print half pyramid using numbers.
7. To check whether the candidate is eligible for voting
8. To check whether the number is buzz number or not

9. To find the GCD and LCM of the given two numbers.


10. To print the prime number from the given range
11. To find an element using the linear search
12. To search an element using binary search
To arrange the elements in an ascending order using
13. selection sort.
To arrange the elements in an ascending order using
14. bubble sort
15. To read and print elements of two – dimensional array
16. To implement functions in string class.

17. To implement functions in stringBuffer class.


Design a class with some specification of methods,
18. variables.
To accept two strings of same length and print the first
character of the first word is followed by the first
19.
character of the second word and so on.
To declare an array to accept ten words. Display the
words which begin with the letter ‘A’ or ‘a’ and also
20. end with the letter ‘A’ or ‘a’.
1. write a java program to check whether the given number is odd or even
import [Link];
class Evenodd
{
public static void main(String args[])
{
int n;
[Link]("Enter the value of n");
Scanner in = new Scanner([Link]);
n=[Link]();
if(n%2==0)
[Link](n+" is even");
else
{
[Link](n+" is odd");
}
}

}
2. write a java program to find the factorial of the given number
import [Link];
class fact
{
public static void main (String[]args)
{
int i=1,n,fact=1;
Scanner in=new Scanner([Link]);
[Link]("Enter the value of n");
n=[Link]();
for(i=1;i<=n;i++)
{
fact=fact*i;
}
[Link]("The factorial is" +fact);

}
}
[Link] a java program to find the area and perimeter of the circle

public class areapericircle


{
private static final double radius = 7.5;

public static void main(String[] args)


{
// Calculate the perimeter of the circle using the constant radius
double perimeter = 2 * [Link] * radius;

// Calculate the area of the circle using the constant radius


double area = [Link] * radius * radius;

// Print the calculated perimeter and area


[Link]("Perimeter is = " + perimeter);
[Link]("Area is = " + area);
}
}
[Link] a java program to print the days of the week using switch case.
public class switchcase
{
public static void main(String[] args) {
int day = 4;
switch (day) {
case 1:
[Link]("Monday");
break;
case 2:
[Link]("Tuesday");
break;
case 3:
[Link]("Wednesday");
break;
case 4:
[Link]("Thursday");
break;
case 5:
[Link]("Friday");
break;
case 6:
[Link]("Saturday");
break;
case 7:
[Link]("Sunday");
break;
}
}
}
[Link] a java program to print inverted half pyramid using *
public class pattern
{

public static void main(String[] args)


{
int rows = 5;

for (int i = rows; i >= 1; --i)


{
for (int j = 1; j <= i; ++j)
{
[Link]("* ");
}
[Link]();
}
}
}
[Link] a java program to print half pyramid using numbers.

public class Pattern1


{
public static void main(String args[])
{
int i, j,number, n=7;
//loop for rows
for(i=0; i<n; i++)
{
number=1;
//loop for columns
for(j=0; j<=i; j++)
{
//prints num
[Link](number+ " ");
//incrementing the value of number
number++;
}
//throws the cursor at the next line after printing each row
[Link]();
}
}
}
[Link] a java program to check whether the candidate is eligible for voting
import [Link].*;
public class Voting {
public static void main(String[] args)
{
// Declaring variables
int age, diff;
// taking user input
Scanner scan = new Scanner([Link]);
[Link]("Please enter your age: ");
age = [Link]();

// Checking condition for voting..


if(age>=18)
{
[Link]("You are eligible for voting.");
}
else
{
diff = (18 - age);
[Link]("Sorry,You can vote after: "+ diff + " years");
}
}
}
[Link] a java program to check whether the given number is buzz number or not
import [Link];

public class BuzzNumber


{
public static void main(String arg[])
{

Scanner in = new Scanner([Link]);

[Link]("Enter a number: ");


int number = [Link]();

if (number % 10 == 7 || number % 7 == 0)
[Link](number + " is a Buzz number.");
else
[Link](number + " is a not Buzz number.");
}
}
[Link] a java program to find the GCD and LCM of the given two numbers.
import [Link].*;

class GFG {

// gcd method returns the GCD of a and b


static int gcd(int a, int b) {

// if b=0, a is the GCD


if (b == 0)
return a;

// call the gcd() method recursively by


// replacing a with b and b with
// modulus(a,b) as long as b != 0
else
return gcd(b, a % b);
}

// lcm() method returns the LCM of a and b


static int lcm(int a, int b, int gcdValue)
{
return [Link](a * b) / gcdValue;
}

// Driver method
public static void main(String[] args) {

int a = 45, b = 35, gcdValue;


gcdValue = gcd(a, b);
// calling gcd() over
[Link]("GCD = " + gcdValue);

// calling lcm() over integers 30 and 20


[Link]("LCM = " + lcm(a, b, gcdValue));
}
}
[Link] a java program to print the prime number from the given range
public class prime
{
public static void main (String[]args)
{
int lower = 1, upper = 20;
for (int i = lower; i <= upper; i++)
if (isPrime (i))
[Link] (i);
}

static boolean isPrime (int n)


{
int count = 0;

// 0, 1 negative numbers are not prime


if (n < 2)
return false;

// checking the number of divisors b/w 1 and the number n-1


for (int i = 2; i < n; i++)
{
if (n % i == 0)
return false;
}

// if reached here then must be true


return true;
}
}
11. write a java program to find an element using the linear search
public class LinearSearch{
public static int linearSearch(int[] arr, int key){
for(int i=0;i<[Link];i++){
if(arr[i] == key){
return i;
}
}
return -1;
}
public static void main(String a[]){
int[] a1= {10,20,30,50,70,90};
int key = 50;
[Link](key+" is found at index: "+linearSearch(a1, key));
}
}
12. write a java program to search an element using binary search

class BinarySearch{
public static void binarySearch(int arr[], int first, int last, int key){
int mid = (first + last)/2;
while( first <= last ){
if ( arr[mid] < key ){
first = mid + 1;
}else if ( arr[mid] == key ){
[Link]("Element is found at index: " + mid);
break;
}else{
last = mid - 1;
}
mid = (first + last)/2;
}
if ( first > last ){
[Link]("Element is not found!");
}
}
public static void main(String args[]){
int arr[] = {10,20,30,40,50};
int key = 30;
int last=[Link]-1;
binarySearch(arr,0,last,key);
}
}
[Link] a java program to arrange the elements in an ascending order using selection
sort.
public class SelectionSort {
public static void selectionSort(int[] arr) {
for (int i = 0; i < [Link] - 1; i++)
{
int index = i;
for (int j = i + 1; j < [Link]; j++){
if (arr[j] < arr[index]){
index = j;//searching for lowest index
}
}
int smallerNumber = arr[index];
arr[index] = arr[i];
arr[i] = smallerNumber;
}
}
public static void main(String a[]){
int[] arr1 = {9,14,3,2,43,11,58,22};
[Link]("Before Selection Sort");
for(int i:arr1){
[Link](i+" ");
}
[Link]();
selectionSort(arr1);//sorting array using selection sort
[Link]("After Selection Sort");
for(int i:arr1){
[Link](i+" ");
}
}
}
[Link] a java program to arrange the elements in an ascending order using bubble
sort
public class BubbleSortExample {
static void bubbleSort(int[] arr) {
int n = [Link];
int temp = 0;
for(int i=0; i < n; i++){
for(int j=1; j < (n-i); j++){
if(arr[j-1] > arr[j]){
//swap elements
temp = arr[j-1];
arr[j-1] = arr[j];
arr[j] = temp;
}
}
}
}
public static void main(String[] args) {
int arr[] ={3,60,35,2,45,320,5};
[Link]("Array Before Bubble Sort");
for(int i=0; i < [Link]; i++){
[Link](arr[i] + " ");
}
[Link]();
bubbleSort(arr);//sorting array elements using bubble sort
[Link]("Array After Bubble Sort");
for(int i=0; i < [Link]; i++){
[Link](arr[i] + " ");
}
}
}
[Link] a java program to read the elements and print two - dimensional array

import [Link];
public class two {
public static void main(String args[]) {
int row, col, i, j;
int arr[][] = new int[10][10];
Scanner scan = new Scanner([Link]);
// enter row and column for array.
[Link]("Enter row for the array (max 10) : ");
row = [Link]();
[Link]("Enter column for the array (max 10) : ");
col = [Link]();
// enter array elements.
[Link]("Enter " + (row * col) + " Array Elements : ");
for (i = 0; i < row; i++) {
for (j = 0; j < col; j++) {
arr[i][j] = [Link]();
}
}
// the 2D array is here.
[Link]("The Array is :\n");
for (i = 0; i < row; i++) {
for (j = 0; j < col; j++) {
[Link](arr[i][j] + " ");
}
[Link]();
}
}
}
[Link] a java program to implement functions in string class.
import [Link].*;
import [Link].*;

// Driver Class
class Test
{
// main function
public static void main (String[] args)
{
String s= "GeeksforGeeks";
// or String s= new String ("GeeksforGeeks");

// Returns the number of characters in the String.


[Link]("String length = " + [Link]());

// Returns the character at ith index.


[Link]("Character at 3rd position = "
+ [Link](3));

// Return the substring from the ith index character


// to end of string
[Link]("Substring " + [Link](3));

// Returns the substring from i to j-1 index.


[Link]("Substring = " + [Link](2,5));

// Concatenates string2 to the end of string1.


String s1 = "Geeks";
String s2 = "forGeeks";
[Link]("Concatenated string = " +
[Link](s2));

// Returns the index within the string


// of the first occurrence of the specified string.
String s4 = "Learn Share Learn";
[Link]("Index of Share " +
[Link]("Share"));

// Returns the index within the string of the


// first occurrence of the specified string,
// starting at the specified index.
[Link]("Index of a = " +
[Link]('a',3));

// Checking equality of Strings


Boolean out = "Geeks".equals("geeks");
[Link]("Checking Equality " + out);
out = "Geeks".equals("Geeks");
[Link]("Checking Equality " + out);

out = "Geeks".equalsIgnoreCase("gEeks ");


[Link]("Checking Equality " + out);

//If ASCII difference is zero then the two strings are similar
int out1 = [Link](s2);
[Link]("the difference between ASCII value is="+out1);
// Converting cases
String word1 = "GeeKyMe";
[Link]("Changing to lower Case " +
[Link]());

// Converting cases
String word2 = "GeekyME";
[Link]("Changing to UPPER Case " +
[Link]());

// Trimming the word


String word4 = " Learn Share Learn ";
[Link]("Trim the word " + [Link]());

// Replacing characters
String str1 = "feeksforfeeks";
[Link]("Original String " + str1);
String str2 = "feeksforfeeks".replace('f' ,'g') ;
[Link]("Replaced f with g -> " + str2);
}
}
17. write a java program to implement functions in stringBuffer class.
class StringBufferExample
{
public static void main(String args[])
{
StringBuffer sb=new StringBuffer("Hello ");
[Link]([Link]());//default 16
[Link]("java");
[Link]([Link]());//now 16
[Link]("java is a language");
[Link]([Link]());
[Link]("Java");
[Link](sb);
[Link](1,"Java");
[Link](sb);
[Link](1,3,"Java");
[Link](sb);
[Link](1,3);
[Link](sb);
[Link]();
[Link](sb);
}
}
18) Design a class with following specification
Class name : Student
Member variables : name: name of the student
Age: age of the student
Mks: marks obtained
Stream: stream allocated
(declare the variable using appropriate with datatypes)
Member methods
Void accept() - Accept name,age and marks usinf methods of Scanner class.
Void allocation() - Allocate the stream as per following criteria:
Mks stream
> = 300 Science and Computer
> = 200 and < 300 Commerce and computer
> = 75 and 200 Arts and Animation
<75 Try again
Void show() - Display student name,age,mks and stream allocated. call all the above methods
using an object.

import [Link];
public class student
{
Scanner sc=new Scanner([Link]);
String name;
int age;
int mks;
String stream;

void accept()
{
[Link]("enter the name of the student");
name=[Link]();
[Link]("enter the age of the student");
age=[Link]();
[Link]("enter the name of the student");
mks=[Link]();
}

void allocation()
{
if(mks>=300)
[Link]("Science and computer");
else if(mks>=200 && mks<300)
[Link]("Commerce and computer");
else if(mks>=75 && mks<200)
[Link]("Arts and Animation");
else
[Link]("try again");

public static void main(String arg[])


{
student ob=new student();
[Link]();
[Link]();
}
}
19) Define a class to accept two strings of same length and form a new word in such a
way that, the first character of the first word is followed by the first character of the
second word and so on.
import [Link];
public class strexam
{
public static void main(String arg[])
{
Scanner sc=new Scanner([Link]);
String stnew="";
[Link]("enter the first string");
String st1=[Link]();
[Link]("enter the second string");
String st2=[Link]();

for(int i=0;i<[Link]();i++)
{
stnew=stnew+[Link](i)+[Link](i);
}
[Link](stnew);
}
}
20) Define a class to declare an array to accept and store ten words. Display only those
words which begin with the letter ‘A’ or ‘a’ and also end with the letter ‘A’ or ‘a’.
EXAMPLE : Input : Hari, Anita, Akash, Amrita, Alina, Devi Rishab, John, Farha, AMITHA
Output: Anita Amrita Alina AMITHA
import [Link];
public class NameWithA {
public static void main(String[] args)
{
String names[] = new String[5];
Scanner sc = new Scanner([Link]);
int l = [Link];
[Link]("Enter 5 name:");
for (int i = 0; i < l; i++)
{
names[i]=[Link]();
}
[Link]("Names are:-");
for (int i = 0; i < l - 1; i++)
{
int lastIndex = names[i].length() - 1;

if(names[i].charAt(0)=='a'||names[i].charAt(0)=='A'||names[i].charAt(lastIndex)=='a'||names[
i].charAt(lastIndex)=='A')
{
[Link](names[i]);
}
}
}
}

You might also like