KEMBAR78
Computer Applications Project Class 11 | PDF | C++ | String (Computer Science)
0% found this document useful (0 votes)
8 views33 pages

Computer Applications Project Class 11

Uploaded by

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

Computer Applications Project Class 11

Uploaded by

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

COMPUTER APPLICATIONS PROJECT

NAME- Vayun Lakhmani


CLASS- XI
SECTION- C
ROLL NUMBER- 28
TOPIC- Arrays And its Implements AND Java
programs.
PHYSICS PROJECT

NAME- Vayun Lakhmani


CLASS- XI
SECTION- C
ROLL NUMBER- 28
TOPIC- Heat And Thermodynamics
MATHEMATICS PROJECT

NAME- Vayun Lakhmani


CLASS- XI
SECTION- C
ROLL NUMBER- 28
TOPIC- Quadratic Equation And Trigonometry
ENGLISH PROJECT

NAME- Vayun Lakhmani


CLASS- XI
SECTION- C
ROLL NUMBER- 28
1) Armstrong Number:
import java.util.*;
class armstrong
{
public static void main()
{ int c= 0,sum=0;
Scanner sc =new Scanner (System.in);
System.out.println ("Enter Number to be checked ");
int n = sc.nextInt();
for (int i= n; i>0; i= i/10)
{
c++;
}
for (int i= n; i>0; i= i/10)
{
int d= i%10;
sum+= (int) Math.pow(d,c);
}
if (sum== n)
System.out.println("Armstrong Number");
else
System.out.println("Not an Armstrong Number");
}
}

Input Output
153 153 is an Armstrong Number

370 370 is an Armstrong Number

123 123 is NOT an Armstrong Number

9474 9474 is an Armstrong Number

Algorithm
1. Start the program.
2. Ask the user to enter a number.
3. Count how many digits the number has (store in variable c).
4. Calculate the sum of each digit raised to the power c:
o Extract each digit from the number.

o Raise the digit to the power c.

o Add this value to a sum variable.

5. Compare the sum with the original number:


o If they are equal, print "Armstrong Number".

o Otherwise, print "Not an Armstrong Number".

6. End the program.

2)Automorphic numbers:
import java.util.*;
class automorphic
{
public static void main()
{ int c= 0;
Scanner sc =new Scanner(System.in);
System.out.println("Enter number to be checked");
int n= sc.nextInt ();
int sq= n*n;
for (int i= n; i>0;i= i/10)
{
c++;
}
int nsq= sq % (int) Math.pow(10,c);
if (nsq==n)
System.out.println ("automorphic Number");
else
System.out.println("Not an automorphic Number");
}

Input Output

25 25 is an Automorphic Number

76 76 is an Automorphic Number

13 13 is NOT an Automorphic Number

6 6 is an Automorphic Number

Algorithm
1. Start the program.
2. Ask the user to enter a number.
3. Calculate the square of the number.
4. Count how many digits the number has.
5. Extract the last digits of the square equal to the number of digits counted.
6. Compare these extracted digits with the original number:
o If they are equal, print "Automorphic Number".
o Otherwise, print "Not an Automorphic Number".

7. End the program.

3)Bubble Sort:
import java.util.*;
class sorting
{
public static void main ()
{ int t;
Scanner sc = new Scanner (System.in);
int a[] = new int [10];
System.out.println ("Enter 10 Numbers to be sorted ");
for (int i=0; i<10;i++)
{
a[i] = sc.nextInt();
}
for (int i= 0; i<10;i++)
{
for(int j= 0; j<9-i; j++)
{
if ( a[j] >a[j+1])
{
t= a[j];
a[j]= a[j+1];
a[j+1]= t;
}

}
}
System.out.println("Sorted Array:");
for (int i= 0; i<10; i++)
{
System.out.println(a[i]+ " ");
}
}
}
Algorithm
Start the program.
1. Ask the user to enter 10 numbers and store them in an array.
2. Use bubble sort to sort the array in ascending order:
o Repeat for each element in the array:

 Compare each pair of adjacent elements.


 If the first is greater than the second, swap them.
o Continue until the array is fully sorted.

3. Print the sorted array.


4. End the program.

Input:
Enter 10 Numbers to be sorted
34 12 5 67 23 89 2 44 90 11
Output:
Sorted Array:
2 5 11 12 23 34 44 67 89 90

4) Write a program to create an array to store 3 integers and print


the largest integer and the smallest integer in that array.
PROGRAM:
import java.util.*; class sort
{
public static void main (String args[])
{ int t=0;
Scanner sc = new Scanner(System.in); System.out.println ("Enter 3 Numbers"); int a[]= new int
[3]; for (int i=0;i<3;i++)
{ a[i]=sc.nextInt(); }
for (int i=0;i<2;i++)
{
for (int j=i+1; j<3; j++)
{ if (a[i] >a[j])
{ t= a[i];
a[i]= a[j]; a[j]=t; }
}
}
System.out.println("largest Number="+a[2]);
System.out.println("Smallest Number="+a[0]);
}
Algorithm
1. Start the program.
2. Ask the user to enter 3 numbers and store them in an array.
3. Sort the array in ascending order by comparing each pair of elements and swapping if
needed:
o For each element, compare it with all following elements.

o Swap if the first is larger than the second.

4. After sorting, the smallest number is at index 0, and the largest is at index 2.
5. Print the largest and smallest numbers.
6. End the program.
Input:
Enter 3 Numbers
25 9 42
Output:
Largest Number = 42
Smallest Number = 9

5)Binary Search:
import java.util.Scanner;
import java.util.Arrays;

public class BinarySearch {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int[] arr = new int[10];

// Accept 10 numbers
System.out.println("Enter 10 numbers:");
for (int i = 0; i < 10; i++) {
arr[i] = scanner.nextInt();
}

// Sort the array (required for binary search)


Arrays.sort(arr);

// Accept number to search


System.out.print("Enter number to search: ");
int target = scanner.nextInt();

// Perform binary search


int low = 0, high = arr.length - 1;
boolean found = false;

while (low <= high) {


int mid = (low + high) / 2;

if (arr[mid] == target) {
found = true;
break;
} else if (arr[mid] < target) {
low = mid + 1;
} else {
high = mid - 1;
}
}

// Output result
if (found) {
System.out.println("Number exists in the array.");
} else {
System.out.println("Number does not exist in the array.");
}

scanner.close();
}
}

Algorithm
1. Start the program.
2. Ask the user to enter 10 numbers and store them in an array.
3. Sort the array in ascending order.
4. Ask the user to enter the number to search for (target).
5. Use binary search to find the target:
o Initialize two pointers: low at the start, high at the end of the array.

o While low is less than or equal to high:

 Find the middle index mid.


 If the middle element is the target, stop and mark as found.
 If the middle element is less than the target, move low to mid + 1.
 Otherwise, move high to mid - 1.
6. Print whether the number exists in the array or not.
7. End the program.
Input:
Enter 10 numbers:
5 12 3 9 21 8 17 4 10 7
Enter number to search: 9
Output:
Number exists in the array.

6) Write a program to input 5 integer elements in an array


and then check the total number of odd and even numbers
out of them and finally display their count with an
appropriate message.
import java .util.*;
class array
{
public static void main (String args[])
{ int odd= 0, even=0;
Scanner sc =new Scanner (System.in);
System.out.println("Enter 5 Numbers");
int a[]= new int[5];
for (int i=0; i<5; i++)
{ a[i]= sc.nextInt();
}
for (int i =0; i<5; i++)
{
if (a[i]%2== 0) even++);
else odd++;
}
System.out.println("Number of even Numbers="+even);
System.out.println("Number of odd Numbers="+odd);
}
}
Algorithm
Start the program.
1. Ask the user to enter 5 numbers and store them in an array.
2. Initialize counters for odd and even numbers to zero.
3. Loop through each number in the array:
o If the number is divisible by 2, increase the even counter.

o Otherwise, increase the odd counter.

4. Print the count of even and odd numbers.


5. End the program.
Input:
Enter 5 Numbers
2 5 8 7 10
Output:
Number of even Numbers = 3
Number of odd Numbers = 2
7) Write a program using Java language to generate the
factorial of a given number up to n times. Example: The
factorial of 5 is = 1*2*3*4*5

import java.util.*;
class factorial
{
public static void main (String args[])
{ int p=1;
Scanner sc =new Scanner (System.in);
System.out.println("Enter the Number");
int n=sc.nextInt();
for (int i=1; i<=n; i++)
{
p= p*i;
}
System.out.println(p);
}
}

Algorithm
1. Start the program.
2. Ask the user to enter a number n.
3. Initialize a variable p to 1 to store the factorial result.
4. Loop from 1 to n:
o Multiply p by the current number in the loop.
5. After the loop ends, print the factorial value stored in p.
6. End the program.

Input:
Enter the Number
5
Output:
Factorial of 5 is 120
8) Write a program in Java to calculate total number of
vowels and consonants present in a given string
import java.util.*;

class vowel
{
public static void main(String args[])
{ int v= 0, c=0;
Scanner sc = new Scanner (System.in);
System.out.println ("Enter String ");
String s =sc.next();
int l= s.length(); // To find the number of characters present in the string
s= s.toUpperCase(); // converts string to upper case
s=s.trim();
for(int i= 0; i<l; i++)
{
char le= s.charAt(i);
if (le=='A' || le=='E' || le=='I' || le== 'O' || le== 'U') // To check Number of vowels
v++;
else
c++;
}
System.out.println ("Number of vowels present are=" +v);
System.out.println ("Number of consonants present are="+c);
}
}

Algorithm
Start the program.
1. Ask the user to enter a string.
2. Convert the string to uppercase and trim any spaces.
3. Initialize vowel counter v and consonant counter c to zero.
4. For each character in the string:
o If the character is a vowel (A, E, I, O, U), increase v.

o Otherwise, increase c.

5. Print the number of vowels and consonants.


6. End the program.

Input:
Enter String
Hello
Output:
Number of vowels present are = 2
Number of consonants present are = 3

9) Write a program using Java language to display a given


string in the vertical manner:
import java.util.*; class vertical
{
public static void main(String args[])
{
Scanner sc = new Scanner (System.in);
System.out.println ("Enter String "); String s =sc.nextLine(); int l= s.length(); s=s.trim(); s=
s.toUpperCase(); for (int i=0; i<l; i++)
{
System.out.println (s.charAt(i));
}
}
}

Algorithm in Simple English


1. Start the program.
2. Ask the user to enter a string.
3. Remove extra spaces at the beginning and end of the string.
4. Convert the string to uppercase letters.
5. For each character in the string:
o Print it on a new line.

6. End the program.

Input:
Enter String
Hello
Output:
H
E
L
L
O
10) Write a program using Java language to enter a
string and check whether it isaPalindrome or not. Note:
Palindrome means characters read from left to right
and vice–versa are identical)

import java.util.*;
class palindrome
{
public static void main (String args[])
{ String t="";
Scanner sc = new Scanner (System.in);
System.out.println ("Enter the String");
String s =sc.next();
int l= s.length();
s= s.toUpperCase();
for (int i=l-1; i>=0; i--)
{
t= t+ s.charAt(i);
} t=t.trim();
if (s.compareTo(t)==0)
System.out.println ("Palindrome String ");
else
System.out.println ("Not a Palindrome String:");
}
}
Algorithm
Start the program.
1. Ask the user to enter a string.
2. Convert the string to uppercase for case-insensitive comparison.
3. Reverse the string and store it in another string t.
4. Compare the original string and the reversed string:
o If they are the same, it is a palindrome.

o Otherwise, it is not a palindrome.

5. Print the result.


6. End the program.
Input:
Enter the String
Madam
Output:
Palindrome String

11) To accept a double dimensional array using scanner


class and sort the rows of double dimensional array .
import java.util.Scanner;
import java.util.Arrays;

public class Sort2DArrayRows {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

// Accept dimensions
System.out.print("Enter number of rows: ");
int rows = scanner.nextInt();

System.out.print("Enter number of columns: ");


int cols = scanner.nextInt();
int[][] array = new int[rows][cols];

// Input elements
System.out.println("Enter elements of the 2D array:");
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
array[i][j] = scanner.nextInt();
}
}

// Sort each row


for (int i = 0; i < rows; i++) {
Arrays.sort(array[i]);
}

// Display sorted array


System.out.println("Sorted array (rows sorted):");
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
System.out.print(array[i][j] + " ");
}
System.out.println();
}

scanner.close();
}
}

Input:
Enter number of rows: 2
Enter number of columns: 3
Enter elements of the 2D array:
935
421
Output:
Sorted array (rows sorted):
359
124
Algorithm to Accept and Sort Rows of a 2D Array:
1. Start the program.
2. Ask the user to enter the number of rows and columns for the 2D array.
3. Create a 2D array with the given number of rows and columns.
4. Use a loop to fill the array:
o For each row:

 For each column in that row:


 Ask the user to enter a number and store it in the array.
5. Use a loop to sort each row of the array:
o For each row:

 Sort the elements in that row in ascending order.


6. Use a loop to display the sorted array:
o For each row:

 Print all the elements in that row.


7. End the program.

12) To accept a double dimensional array using scanner


class and sort the columns of double dimensional array .
import java.util.Scanner;

public class Sort2DArrayColumns {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

// Accept dimensions
System.out.print("Enter number of rows: ");
int rows = scanner.nextInt();

System.out.print("Enter number of columns: ");


int cols = scanner.nextInt();

int[][] array = new int[rows][cols];

// Input array elements


System.out.println("Enter elements of the 2D array:");
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
array[i][j] = scanner.nextInt();
}
}

// Sort each column


for (int col = 0; col < cols; col++) {
// Simple bubble sort on column
for (int i = 0; i < rows - 1; i++) {
for (int j = 0; j < rows - i - 1; j++) {
if (array[j][col] > array[j + 1][col]) {
// Swap
int temp = array[j][col];
array[j][col] = array[j + 1][col];
array[j + 1][col] = temp;
}
}
}
}

// Display the sorted array


System.out.println("Sorted array (columns sorted):");
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
System.out.print(array[i][j] + " ");
}
System.out.println();
}

scanner.close();
}
}

Input:
Enter number of rows: 3
Enter number of columns: 3
Enter elements:
987
654
321
Output:
Sorted array (columns sorted):
321
654
987
Algorithm to Sort Columns of a 2D Array:
1. Start the program.
2. Ask the user to enter the number of rows and columns for the 2D array.
3. Create a 2D array with the given number of rows and columns.
4. Use a loop to fill the array:
o For each row:

 For each column in that row:


 Ask the user to enter a number and store it in the array.
5. Sort each column using a sorting technique:
o For each column:

 Use a nested loop to compare and swap elements in that column.


 Make sure elements in each column are arranged in ascending order
(smallest to largest from top to bottom).
6. Display the sorted array:
o For each row:

 Print all elements in that row.


7. End the program.

13) Write program in java to calculate the HCF of a


number (to be accepted using scanner) using reccursion
import java.util.Scanner;

public class HCFRecursive {


// Recursive method to calculate HCF
public static int findHCF(int a, int b) {
if (b == 0)
return a;
else
return findHCF(b, a % b);
}

public static void main(String[] args) {


Scanner scanner = new Scanner(System.in);

// Accept two numbers


System.out.print("Enter first number: ");
int num1 = scanner.nextInt();

System.out.print("Enter second number: ");


int num2 = scanner.nextInt();

// Calculate HCF using recursion


int hcf = findHCF(num1, num2);

// Display result
System.out.println("HCF of " + num1 + " and " + num2 + " is: " + hcf);

scanner.close();
}
}

Input:
Enter first number: 48
Enter second number: 18
Output:
HCF of 48 and 18 is: 6

Algorithm to Calculate HCF of Two Numbers Using Recursion:


1. Start the program.
2. Ask the user to enter two numbers.
o Read the first number and store it in variable num1.

o Read the second number and store it in variable num2.

3. Call a recursive function to find the HCF of num1 and num2.


4. Inside the recursive function (let's call it findHCF(a, b)):
o If b is equal to 0:

 Return a (because the HCF is found).


o Otherwise:

 Call findHCF(b, a % b) again (this repeats the process with smaller


numbers).
5. Display the result (HCF) to the user.
6. End the program.

14) Print Fibonacci Series Using Recursion


import java.util.Scanner;
public class FibonacciRecursive {
// Recursive method to get the nth Fibonacci number
public static int fibonacci(int n) {
if (n == 0)
return 0;
else if (n == 1)
return 1;
else
return fibonacci(n - 1) + fibonacci(n - 2);
}

public static void main(String[] args) {


Scanner scanner = new Scanner(System.in);

// Accept number of terms from user


System.out.print("Enter the number of terms in Fibonacci series: ");
int terms = scanner.nextInt();

System.out.println("Fibonacci Series:");
for (int i = 0; i < terms; i++) {
System.out.print(fibonacci(i) + " ");
}

scanner.close();
}
}

Input:
Enter the number of terms in Fibonacci series: 5
Output:
Fibonacci Series:
01123
Algorithm to Print Fibonacci Series Using Recursion:
1. Start the program.
2. Ask the user to enter how many terms of the Fibonacci series they want.
3. Create a recursive function called fibonacci(n):
o If n is 0 → return 0 (base case).

o If n is 1 → return 1 (base case).

o Otherwise → return fibonacci(n - 1) + fibonacci(n - 2).

4. Use a loop to print each term in the Fibonacci series:


o For i from 0 to (number of terms - 1):

 Call the recursive function fibonacci(i).


 Print the returned value.
5. End the program.

15) To check a number to be duck number using java. A


Duck Number is a number that contains at least one
zero digit, but no leading zeros (i.e., the number doesn't
start with zero).
import java.util.Scanner;

public class DuckNumberCheck {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

System.out.print("Enter a number: ");


String num = scanner.nextLine();

boolean isDuck = false;

// Check leading zero


if (num.charAt(0) == '0') {
isDuck = false;
} else {
// Check for zero in other places
for (int i = 1; i < num.length(); i++) {
if (num.charAt(i) == '0') {
isDuck = true;
break;
}
}
}

if (isDuck) {
System.out.println(num + " is a Duck Number.");
} else {
System.out.println(num + " is NOT a Duck Number.");
}

scanner.close();
}
}

Input:
Enter a number: 2034
Output:
2034 is a Duck Number.
Algorithm to Check Duck Number
1. Start the program.
2. Ask the user to enter a number (read it as a string).
3. Check the first digit of the number:
o If the first digit is '0', then the number is NOT a Duck Number.

o Otherwise, proceed to the next step.

4. Look at the rest of the digits in the number:


o Scan each digit from the second character to the end.

o If you find at least one '0' in these digits, then the number IS a Duck Number.

o If no '0' is found, then it is NOT a Duck Number.

5. Print the result:


o If it is a Duck Number, print "[number] is a Duck Number."

o Otherwise, print "[number] is NOT a Duck Number."

6. End the program.

You might also like