0% found this document useful (0 votes)
20 views

SAMRIDHI

Uploaded by

saarthak0427
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)
20 views

SAMRIDHI

Uploaded by

saarthak0427
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/ 115

GREENFIELDS SCHOOL

ICSE Project File


Session 2024-2025
Subject: COMPUTER APPLICATIONS

INDEX NO:
Name of Student: Sarthak Gupta
Class/Section: 10th- Science
Submitted To: Mr. Asif Ismail
1
INDEX
PROGRAM NO. PROGRAM PAGE NO. TEACHER’S
NAME SIGN
PREFACE
5
ACKNOWLEDGEMENT
6
Count
1 7
Count vowels
2 9
Palindrome word
3 11
Piglatin word
4 13
Alphabetical order
5 15
Initials
6 17
Frequency
7 19
Replace vowels
8 21
Removing initials
9 23
Print a
10 25
Abbreviated form
11 27
Print palindromic
12 words 29
13 31

2
14 33
15 34
16 35
17 37
18 39
1 41
2 43
3 45
4 47
5 49
6 52
7 61
8 63
9 65
10 68
11 71
12 74
13 77
3
14 79
15 81
16 83
17 84
18 87
19 89
20 91
Pattern
1 93
Pattern
2 95
Pattern
3 97
Pattern
4 99
Pattern
5 101
Niven and neon
6 number 103
Armstrong and
7 palindrome number 105
Minimum and
8 maximum number 107
Prime and composite
9 number 109
Special and perfect
10 number 114
BIBLIOGRAPHY
115
4
PREFACE

In this file I will show you about the 50


java programs with their output. And the
topics related to it.

• Single dimensional array programs


• Double dimensional array programs
• String programs
• Switch Case programs

SARTHAK GUPTA
10 th-A

5
ACKNOWLEDGEMENT

I Sarthak Gupta would like to express my


special thanks to my mentor Mr Asif
Ismail for his time and efforts he
provided through out the time. Your
useful suggestions and advice were
really helpful to me during the project’s
completion. In this aspect, I am eternally
grateful to you. Secondly, I would also
like to thank my parents and friends who
helped me a lot in finalizing this whole
java project.
SARTHAK GUPTA
10 th-A

6
STRING PROGRAMS

1-Write a program to input a sentence and count the number of words, alphabets and
digits present in the sentence.

import java.util.*;
public class string1
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("enter a string");
String st=sc.nextLine();
int sp=0,a=0,d=0;
for(int i=0;i<st.length();i++)
{
char ch=st.charAt(i);
if(ch==' ')
sp++;
if((ch>='A' && ch<='Z')||(ch>='a' && ch<='z'))
a++;
if(ch>='0' && ch<='9')
d++;
}

7
System.out.println ("number of words"+sp);
System.out.println ("alphabets"+a);
System.out.println ("number of digits"+d);
}
}

Output:

8
2-Write a program to accept a string and count as well as display the number of
vowels.

import java.util.*;
public class string2
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("enter a string");
String st=sc.nextLine();
int v=0;
for(int i=0;i<st.length();i++)
{
char ch=st.charAt(i);
if(ch=='a'|| ch=='e'|| ch=='i'|| ch=='o'|| ch=='u'|| ch=='A'|| ch=='E'|| ch=='I'||
ch=='0'|| ch=='U')
v=v+1;
}
System.out.println ("number of vowels"+v);
}
}

9
Output:

10
3-Write a program to accept a word and check whether the word is palindrome or not.

import java.util.*;
public class string3
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("enter a string");
String st=sc.next();
String str=" ";char ch=0;
for(int i=0;i<st.length();i++)
{
ch=st.charAt(i);
str=ch+str;
}
if(st.equals(str)==true)
System.out.println(" palindrome word");
else
System.out.println(" not a palindrome word");
}
}

11
Output:

12
4- Write a program to accept a word and display the same piglatin form by using the
following steps.

import java.util.*;
public class string4
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("enter a string");
String st=sc.nextLine();
st=st.toUpperCase();
String str=" ";
String v=" ";
String z=" ";
int i;
for( i=0;i<st.length();i++)
{
char ch=st.charAt(i);
if(ch=='A'|| ch=='E'|| ch=='I'|| ch=='O'|| ch=='Z')
{
break;
}
}
v=st.substring(i);
z=st.substring(0,i);

13
str=v+z+"AY";
System.out.println ("piglatin"+str);
}
}

Output:

14
5-Write a program to accept a string and print it in alphabetical order of its letters.

import java.util.*;
public class string5
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("enter a string");
String st=sc.nextLine();
char ch=0;
for(int a=65;a<=90;a++)
{
for(int i=0;i<st.length();i++)
{
ch=st.charAt(i);
if((ch==(char)a)||ch==(char)(a+32))
System.out.print (ch);
}
}
}
}

15
Output:

16
6- Write a program to enter a sentence. Frame a word by joining all the first character
of each word of the sentence and display the word.

import java.util.*;
public class string6
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("enter a string");
String st=sc.nextLine();
st=' '+st;
char ch=0; String st1=" ";
for(int i=0;i<st.length();i++)
{
ch=st.charAt(i);
if(ch==' ')
st1+=st.charAt(i+1);
}
System.out.println ("converted string"+ st1);
}
}

17
Output:

18
7-Write a program to find the frequency of the following string program.

import java.util.*;
public class string7
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("enter a string");
String st=sc.nextLine();
int c=0;
char ch='\u0000';
for(int a=65;a<=90;a++)
{
c=0;
for(int i=0;i<st.length();i++)
{
ch=st.charAt(i);
if(ch==(char)a)
c++;
}
if(c>0)
System.out.println ((char)a+"="+c);
}
}
}

19
Output:

20
8- Write a program to input a word and replace all the vowels of the word with the
next character alphabetically.

import java.util.*;
public class string8
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("enter a string");
String st=sc.nextLine();
String st1=" ";
st=st.toUpperCase();
for(int i=0;i<st.length();i++)
{
char ch=st.charAt(i);
if(ch=='A' ||ch=='E' || ch=='I' || ch=='O'|| ch=='U')
st1+=(char)(ch+1);
else
st1+=ch;
}
System.out.println(st1);
}
}

21
Output:

22
9-Write a program to remove all the initials of the following string.

import java.util.*;
public class string9
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("enter a string");
String st=sc.nextLine();
String st1=" ";
int up=0;char ch=0;
for(int i=0;i<st.length();i++)
{
ch=st.charAt(i);
if(ch>='A' && ch<='Z')
up++;
else
st1+=ch;
}
System.out.println(st1);
System.out.println ("removed string"+up); }
}

23
Output:

24
10-Write a program to input a sentence and print all the ‘a’s present in it.

import java.util.*;
public class string10
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("enter a string");
String st=sc.nextLine();
String st1=" ";
int l,cw=0;char ch,ch1;
for(int i=0;i<st.length();i++)
{
ch=st.charAt(i);
if(ch>='A' && ch<='Z')
ch1=(char)(ch+32);
else
if(ch>'a' && ch<'z')
ch1=(char)(ch-32);
else
{
ch1=ch;
st1=st1+ch1;
}
}

25
System.out.println("old string"+st);
System.out.println ("converted string"+st1);
}
}

Output:

26
11-Writ a program to input full name of a person and print its abbreviated form.

import java.util.*;
public class string11
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("enter a string");
String st=sc.nextLine();
st=" "+st;
String st1=" ";
int l,sp;char ch;
l=st.length();
sp=st.lastIndexOf(' ');
for(int i=0;i<sp;i++)
{
ch=st.charAt(i);
if(ch==' ')
st1+=st.charAt(i+1)+".";
}
st1+=st.substring(sp+1);
System.out.println("old string"+st);
System.out.println ("converted string"+st1);
}
}

27
Output:

28
12-Write a program to input a sentence and print the palindromic words in the
sentence.

import java.util.*;
public class string12
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("enter a string");
String st=sc.nextLine();
st=" "+st;
String wd=" ",rev=" ";
int l,sp;char ch;
l=st.length();
for(int i=0;i<l;i++)
{
ch=st.charAt(i);
if(ch!=' ')
{
wd+=ch;
rev=ch+rev;
}
else
{
if(wd.equalsIgnoreCase(rev))

29
{
System.out.println(wd+" ");
}
wd=" ";
rev=" ";
}
}
System.out.println(wd+ " ");
}
}

Output:

30
13-Write a program to input a sentence and a word. Count the number of times the
word is in the sentence.

import java.util.*;
public class string13
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("enter a string");
String st=sc.nextLine();
st=" "+st;
String wd,extwd=" ";
int l,c=0;char ch;
l=st.length();
System.out.println("enter a word to count");
wd=sc.next();
for(int i=0;i<l;i++)
{
ch=st.charAt(i);
if(ch!=' ')
{
extwd+=ch;
}
else
{

31
if(wd.equalsIgnoreCase(extwd))
c++;
extwd=" ";
}
}

System.out.println(" number of words"+wd+ ": "+c);


}
}

Output:

32
14-Write a program to input a word and print in the following pattern.

import java.util.*;
public class string14
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("enter a word");
String wd=sc.next();
wd=wd.toUpperCase();
String extwd=" ";
int l;char ch;
l=wd.length();
for(int i=0;i<l;i++)
{
extwd=wd.substring(0,1-i);
System.out.println(extwd);
}
}
}

33
Output:

34
15-Write a program to enter a string and check whether it is unique string or not.

import java.util.*;
public class string15
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("enter a string");
String st=sc.nextLine();
st=st.toUpperCase();
String wd=" ",rev=" ";
int l,n=0;char ch,ch1;
l=st.length();
for(int i=0;i<l;i++)
{
ch=st.charAt(i);
for(int j=i+1;j<l-i;j++)
{
ch1=st.charAt(j);
if(ch==ch1)
{
n++;
break;
}
}

35
}
if(n>=1)
System.out.println("not an unique stringe");
else
System.out.println("unique string");
}
}

Output:

36
16-Write a program to accept a string. Convert the string to upper case. Count and
output the number of double letter sequences that exist in the string.
import java.util.*;
public class string16
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("enter a string");
String st=sc.nextLine();
int l,c=0;char ch,ch1;
l=st.length();
for(int i=0;i<l-1;i++)
{
ch=st.charAt(i);
ch1=st.charAt(i+1);
if(Character.isLetter(ch) && Character.isLetter(ch1) &&
(ch==ch1))
c++;
}
System.out.println(c+ " ");

37
}
}

38
17-Write a program to merge two strings and print the output in there ASCII value.
import java.util.*;
public class string17
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("enter to string");
String st=sc.next();
String str=sc.next();
st=st.toUpperCase();
str=str.toUpperCase();
String str1=sc.nextLine();
int l;char ch,ch1;
l=st.length();
for(int i=0;i<l;i++)
{
ch=st.charAt(i);
ch1=str.charAt(l-(i+1));
str1+=ch+ch1;
}
System.out.println(str1+ " ");

39
}
}

40
18-Write a program to print the following pattern.
import java.util.*;
public class string14
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("enter a word");
String wd=sc.next();
wd=wd.toUpperCase();
String extwd=" ";
int l;char ch;
l=wd.length();
for(int i=0;i<l;i++)
{
extwd=wd.substring(0,l-i);
System.out.println(extwd);
}
}
}

41
42
ARRAY PROGRAMS
1-Write a program to enter 10 numbers and find a number among them.
import java.util.*;
public class array1
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int a[]=new int[10];
System.out.println(" enter 10 numbers");
for(int i=0;i<10;i++)
{
a[i]=sc.nextInt();
}
System.out.println("enter a number to be searched");
int ns=sc.nextInt();
int k=0;
for(int i=0;i<10;i++)
{
if(a[i]==ns)
{
k=1;
break;
}

43
}
if(k==1)
System.out.println("numbers found");
else
System.out.println("numbers not found");
}
}

44
2-Write a program to enter 10 city names and find one among them.
import java.util.*;
public class array2
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
String a[]=new String[10];
System.out.println(" enter 10 numbers");
for(int i=0;i<10;i++)
{
a[i]=sc.next();
}
System.out.println("enter city names to be searched");
String ns=sc.next();
int k=0;
for(int i=0;i<10;i++)
{
if(a[i].equals(ns))
{
k=1;
break;
}
}
if(k==1)
System.out.println("city name found");

45
else
System.out.println("city name not found");
}
}

46
3-Write a program to enter 10 numbers through binary search technique.
import java.util.*;
public class array3
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int a[]=new int[10];
System.out.println(" enter 10 numbers");
for(int i=0;i<10;i++)
{
a[i]=sc.nextInt();
}
System.out.println("enter a number to be searched");
int ns=sc.nextInt();
int k=0,f=0,l=9,p;
for(int i=0;i<10;i++)
{
while(f<=l)
{
p=(f+l)/2;
if(a[p]<ns)
f=p+1;
if(a[p]>ns)
l=p-1;
if(a[p]==ns)

47
{
k=1;
break;
}
}
}
if(k==1)
System.out.println("numbers found");
else
System.out.println("numbers not found");
}
}

48
4- Write a program to store the numbers in a 3*3 matrix and assign the transposed
matrix in another array and display it.
import java.util.*;
public class array4
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int i,j;
int m[][]=new int[3][3];
int n[][]=new int[3][3];
System.out.println("enter elements");
for( i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
m[i][j]=sc.nextInt();
}
}
System.out.println("original array");
for( i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
System.out.print(m[i][j]+" ");
}

49
System.out.println();
}
for( i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
n[i][j]=m[j][i];
}
}
System.out.println("transposed value");
for( i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
System.out.print(n[i][j]+" ");
}
System.out.println();
}
}
}

50

51
5- Write a program to input elements in an array of size m*m and print the sum of left
diagonal and product of the right diagonal.
import java.util.*;
public class array5
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int i,m,j,sl=0,pr=1;
System.out.println(" enter size");
m=sc.nextInt();
int ar[][]= new int[m][m];
for( i=0;i<m;i++)
{
for(j=0;j<m;j++)
{
ar[i][j]=sc.nextInt();
}
}
System.out.println("original array");
for( i=0;i<m;i++)
{
for(j=0;j<m;j++)
{
System.out.print(ar[i][j]+" ");
}

52
System.out.println();
}
for( i=0;i<m;i++)
{
for(j=0;j<m;j++)
{
if(i==j)
sl+=ar[i][j];
if((i+j)==(m-1))
pr*=ar[i][j];
}
System.out.println("sum of left diagonal"+sl);
System.out.println("product of right diagonal"+pr);
}

53
6-Write a program to create an array of 20 elements and input 19 elements. Accept the
index position to insert a number in the array using insertion logic.
import java.util.*;
public class array6
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int i,j,n,p;
int m[]=new int[20];
System.out.println("enter elements");
for( i=0;i<19;i++)
{
m[i]=sc.nextInt();
}
System.out.println("enter a number to be inserted");
n=sc.nextInt();
System.out.println("enter a position to be inserted");
p=sc.nextInt();
if(p>=0 && p<=19)
{
for(i=19;i>p;i--)
m[i]=m[i=1];
m[p]=n;
}

54
for(i=0;i<20;i++)
{
System.out.println(m[i]+ " ");
}

}
}

55
7- Write a program to create an array of 10 elements. Accept the index position and
delete the number in the position by using deletion logic.
import java.util.*;
public class array7
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int i,j,n,p;
int m[]=new int[10];
System.out.println("enter a number");
for( i=0;i<10;i++)
{
m[i]=sc.nextInt();
}
System.out.println("enter a position to delete the number");
p=sc.nextInt();
if(p>=0 && p<=9)
{
for(i=p;i<9;i++)
{
m[i]=m[i+1];
}
m[9]=0;
}

56
for(i=0;i<9;i++)
{
System.out.print(m[i]+ " ");
}
}
}

57
8- Write a program to merge two array elements and display the new array.
import java.util.*;
public class array8
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int m,n,p;int i,j;
System.out.println(" length of first array");
m=sc.nextInt();
System.out.println(" length of second array");
n=sc.nextInt();
System.out.println("length of merged array");
p=m+n;
int ar1[]=new int[m];
int ar2[]=new int[n];
int ar3[]=new int[p];
for(i=0;i<m;i++)
{
ar1[i]=sc.nextInt();
}
for(i=0;i<n;i++)
{
ar2[i]=sc.nextInt();
}

58
for(i=0;i<m;i++)
{
ar3[i]=ar1[i];
}
j=m;
for(i=0;i<n;i++)
{
ar3[j]=ar2[i];
j++;
}
System.out.print("merged array");
for(i=0;i<p;i++)
{
System.out.print(ar3[i]+":");
}
}
}

59
60
9-Write a program to input 10 numbers in an array and sort the numbers in ascending
order by using bubble sort technique.
import java.util.*;
public class array9
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int i,j,t;
int ar[]=new int[10];
for(i=0;i<10;i++)
{
ar[i]=sc.nextInt();
}
for(i=0;i<9;i++)
{
for(j=0;j<9-i;j++)
{
if(ar[j]>ar[j+1])
{
t=ar[j];
ar[j]=ar[j+1];
ar[j+1]=t;
}
}
}

61
for(i=0;i<10;i++)
{
System.out.print(ar[i]+ " ");
}
}
}

62
10-Write a program to input 10 numbers in an array and sort the numbers in descending
order by using selection sort technique.
import java.util.*;
public class array10
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int i,j,t,min,m;
int ar[]=new int[10];
for(i=0;i<10;i++)
{
ar[i]=sc.nextInt();
}
for(i=0;i<9;i++)
{
min=ar[i];
m=i;
for(j=i+1;j<10;j++)
{
if(ar[j]<min)
{
min=ar[j];
m=j;
}
}

63
t=ar[m];
ar[m]=ar[i];
ar[i]=t;
}
for(i=0;i<10;i++)
{
System.out.print(ar[i]+ " ");
}
}
}

64
11- Write a program to swap first row with fourth row and vice versa in 4*4 matrix.
import java.util.*;
public class array11
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int a[][]=new int[4][4];
System.out.println(" enter elements");
int i,j;int t=0;
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
a[i][j]=sc.nextInt();
}
}
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
System.out.print(a[i][j]+ " ");
}
System.out.println();
}
for(i=0;i<4;i++)

65
{
t=a[0][i];
a[0][i]=a[3][i];
a[3][i]=t;
}
System.out.println("converted array");
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
System.out.print(a[i][j]+ " ");
}
System.out.println();
}
}
}

66
67
12-Write a program to swap first column with fourth column and vice versa in 4*4
matrix.
import java.util.*;
public class array12
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int a[][]=new int[4][4];
System.out.println(" enter elements");
int i,j;int t=0;
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
a[i][j]=sc.nextInt();
}
}
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
System.out.print(a[i][j]+ " ");
}
System.out.println();
}

68
for(i=0;i<4;i++)
{
t=a[i][0];
a[i][0]=a[i][3];
a[i][3]=t;
}
System.out.println("converted array");
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
System.out.print(a[i][j]+ " ");
}
System.out.println();
}
}
}

69
70
13-Write a program to swap second row with fourth row and vice versa in 4*4 matrix.
import java.util.*;
public class array13
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int a[][]=new int[4][4];
System.out.println(" enter elements");
int i,j;int t=0;
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
a[i][j]=sc.nextInt();
}
}
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
System.out.print(a[i][j]+ " ");
}
System.out.println();
}
for(i=0;i<4;i++)

71
{
t=a[1][i];
a[1][i]=a[2][i];
a[2][i]=t;
}
System.out.println("converted array");
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
System.out.print(a[i][j]+ " ");
}
System.out.println();
}
}
}

72
73
14- Write a program to swap second column with fourth column and vice versa in a 4*4
matrix.
import java.util.*;
public class array14
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int a[][]=new int[4][4];
System.out.println(" enter elements");
int i,j;int t=0;
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
a[i][j]=sc.nextInt();
}
}
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
System.out.print(a[i][j]+ " ");
}
System.out.println();
}

74
for(i=0;i<4;i++)
{
t=a[i][1];
a[i][1]=a[i][2];
a[i][2]=t;
}
System.out.println("converted array");
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
System.out.print(a[i][j]+ " ");
}
System.out.println();
}
}
}

75
76
15- Write a program to print the sum of boundary elements as well as non-boumdary
elements.
import java.util.*;
public class array15
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int a[][]=new int[4][4];
System.out.println(" enter elements");
int i,j;int bs=0;int nbs=0;
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
a[i][j]=sc.nextInt();
}
}
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
if((i>0 && i<3)&&(j>0 && j<3))
nbs+=a[i][j];
else
bs+=a[i][j];

77
}
}
System.out.println("boundary elemets"+bs);
System.out.println("non boundary elemets"+nbs);
}
}

78
16- Write a program to print boundary elements of 4*4 matrix.
import java.util.*;
public class array16
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int a[][]=new int[3][3];
System.out.println(" enter elements");
int i,j;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
a[i][j]=sc.nextInt();
}
}
System.out.println(" boundary elements");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
if((i==0)||(i==3) ||(j==0)||(j==3))
System.out.print(a[i][j]+ " ");
else
System.out.print(" ");

79
}
}
}
}

80
17-Write a program to store numbers in a 4*4 matrix. Print the original matrix and the
diagonal matrix.
import java.util.*;
public class array17
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int a[][]=new int[4][4];
System.out.println(" enter elements");
int i,j;
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
a[i][j]=sc.nextInt();
}
}
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
System.out.print(a[i][j]+ " ");
}
System.out.println();
}

81
for(i=0;i<4;i++)
{
for(j=0;j<3;j++)
{
if((i==j)||(i+j==3))
System.out.print(a[i][j]+" ");
else
System.out.print(" ");
}
System.out.println(" ");
}
}

82
83
18- Write a program to accept number in a 3*3 matrix. Check whether the number is
symmetric or not. Square matrix is said to be symmetric if the elements of its row and
its column are equal to the elements of its row and its column.
import java.util.*;
public class array18
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int a[][]=new int[3][3];
System.out.println(" enter elements");
int i,j;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
a[i][j]=sc.nextInt();
}
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
System.out.print(a[i][j]+ " ");
}

84
System.out.println();
}
int k=0;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
if(a[i][j]!=a[j][i])
{
k=1;
}
}
}
if(k==0)
System.out.println("Symmetrical matrix");
else
System.out.println("not a Symmetrical matrix ");
}

85
86
19-Write a program to store the number in a 4*4 matrix in double dimensional array.
Find the sum of numbers of each row and sum of the numbers of each column of the
matrix.
import java.util.*;
public class array19
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int a[][]=new int[2][2];
System.out.println(" enter elements");
int i,j;
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
a[i][j]=sc.nextInt();
}
}
int s=0;
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
s+=a[i][j];
System.out.println("sum of row"+i+"is"+s);

87
}
}
System.out.println("converted array");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
s+=a[i][j];
System.out.println("sum of column"+j+"is"+s);
}
}
}
}

88
89
20-Write a program to store number in 4*4 matrix in a double dimensional array. Find
the sum of the numbers of the left diagonal and the sum of the numbers of the right
diagonal.
import java.util.*;
public class array20
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int a[][]=new int[4][4];
System.out.println(" enter elements");
int i,j;
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
a[i][j]=sc.nextInt();
}
}
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
System.out.print(a[i][j]+ " ");
}
System.out.println();

90
}
System.out.println("sum of diagonals");
{
int k=3,rd=0,ld=0;
for(i=0;i<4;i++)
{
ld+=a[i][i];
rd+=a[i][k];
k=k-1;
}
System.out.println("left diagonal"+ld);
System.out.println("right diagonal"+rd);
}
}
}

91
92
SWITCH CASE PROGRAMS
1-Write a program to present the following pattern by using switch case.
import java.util.*;
public class pattern1
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("enter your choice");
int ch= sc.nextInt();
switch(ch)
{
case 1:
for(int i=1;i<=5;i++)
{
for(int j=1;j<=i;j++)
{
System.out.print(j+" ");
}
System.out.println();
}
break;
case 2:
for(int i=1;i<=5;i++)

93
{
for(int j=1;j<=i;j++)
{
System.out.print(i+" ");
}
System.out.println();
}
break;
}

}
}

94
2-Write a program to present the following patterns by using switch case.

import java.util.*;
public class pattern2
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("enter your choice");
int ch= sc.nextInt();
switch(ch)
{
case 1:
int a=1;
for(int i=1;i<=5;i++)
{
for(int j=1;j<=i;j++)
{
System.out.print(a+" ");
a++;
}
System.out.println();
}
break;
case 2:
for(int i=1;i<=5;i++)

95
{
int k=1;
for(int j=1;j<=i;j++)
{
System.out.print(k+" ");
k=k+2;
}
System.out.println();
}
break;
}

96
3-Write a program to present the following patterns by using switch case.

import java.util.*;
public class pattern3
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("enter your choice");
int ch= sc.nextInt();
switch(ch)
{
case 1:
for(int i=1;i<=5;i++)
{
for(int j=1;j<=i;j++)
{
if(j%2==0)
System.out.print(0+" ");
else
System.out.print(1+" ");
}
System.out.println();
}
break;
case 2:

97
for(int i=5;i>=1;i--)
{
for(int j=1;j<=i;j++)
{
System.out.print(i+" ");
}
System.out.println();
}
break;
}

}
}

98
4-Write a program to present the following patterns by using switch case.
import java.util.*;
public class pattern4
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("enter your choice");
int ch= sc.nextInt();
switch(ch)
{
case 1:
for(int i=7;i>=1;i=i-2)
{
for(int j=1;j<=i;j++)
{
System.out.print(j+" ");
}
System.out.println();
}
break;
case 2:
for(int i=1;i<=5;i++)
{
for(int j=5;j>=i;j=j-1)

99
{
System.out.print(j+" ");
}
System.out.println();
}
}
}
}

100
5-Write a program to present the following patterns by using switch case.
import java.util.*;
public class pattern5
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("enter your choice");
int ch= sc.nextInt();
switch(ch)
{
case 1:
for(int i=1;i<=5;i++)
{
for(int j=1;j<=i;j++)
{
System.out.print("*"+" ");
}
System.out.println();
}
break;
case 2:
for(int i=1;i<=5;i++)
{
for(int j=1;j<=i;j++)

101
{
System.out.print("#"+" ");
}
System.out.println();
}
break;
}

}
}

6-Write a program to check the niven number and neon number using switch case.

102
import java.util.*;
public class number1
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("enter your choice");
int ch= sc.nextInt();
System.out.println("enter a number");
int n= sc.nextInt();
int i,s=0;
switch(ch)
{
case 1:
int d;
for( i=n;i>0;i=i/10)
{
d=i%10;
s+=d;
}
if(n%s==0)
System.out.println("niven number");
else
System.out.println("not a niven number");
break;
case 2:

103
for(i=n;i>0;i=i/10)
{
d=i%10;
s+=d;
}
if(n==s)
System.out.println("neon number");
else
System.out.println("not a neon number");
break;
}
}

7-Write a program to check Armstrong and Palindrome number by using switch case.

104
import java.util.*;
public class number2
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("enter your choice");
int ch= sc.nextInt();
System.out.println("enter a number");
int n= sc.nextInt();
int i,s=0;
switch(ch)
{
case 1:
int d;
for( i=n;i>0;i=i/10)
{
d=i%10;
s+=(d*d*d);
}
if(s==n)
System.out.println("armstrong number");
else
System.out.println("not an armstrong number");
break;
case 2:

105
int r=0;
for(i=n;i>0;i=i/10)
{
d=i%10;
r=(r*10)+d;
}
if(r==n)
System.out.println("palindrome number");
else
System.out.println("not a palindrome number");
break;
}
}
}

8-Write a program to check the minimum and maximum number by using switch case.
106
import java.util.*;
public class number2
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("enter your choice");
int ch= sc.nextInt();
System.out.println("enter a number");
int n= sc.nextInt();
int i,s=0;
switch(ch)
{
case 1:
int d;
for( i=n;i>0;i=i/10)
{
d=i%10;
s+=(d*d*d);
}
if(s==n)
System.out.println("armstrong number");
else
System.out.println("not an armstrong number");
break;
case 2:

107
int r=0;
for(i=n;i>0;i=i/10)
{
d=i%10;
r=(r*10)+d;
}
if(r==n)
System.out.println("palindrome number");
else
System.out.println("not a palindrome number");
break;
}
}
}

9-Write a program to check prime and composite numbers by using switch case.
108
import java.util.*;
public class number4
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("enter your choice");
int ch= sc.nextInt();
System.out.println("enter a number");
int n= sc.nextInt();
int i,c=0;
switch(ch)
{
case 1:
for( i=1;i<=n;i++)
{
if(n%i==0)
{
c++;
}
}
if(c==2)
System.out.println("Prime number");
else
System.out.println("not a Prime number");
break;

109
case 2:
for( i=1;i<=n;i++)
{
if(n%i==0)
{
c++;
}
}
if(c>2)
System.out.println("Composite number");
else
System.out.println("not a Composite number");
break;
}
}
}
}

110
111
10-Write a program to check the special number and perfect number by using switch
case.
import java.util.*;
public class number5
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("enter your choice");
int ch= sc.nextInt();
System.out.println("enter a number");
int n= sc.nextInt();
int i,s=0;
switch(ch)
{
case 1:
int j,d,f=1;
for( i=n;i>0;i=i/10)
{
d=i%10;
for(j=1;j<=d;j++)
{
f*=j;
}
s+=f;
f=1;

112
}
if(s==n)
System.out.println("Special number");
else
System.out.println("not a Special number");
break;
case 2:
for( i=1;i<n;i++)
{
if(n%i==0)
{
s+=i;
}
}
if(n==s)
System.out.println("Perfect number");
else
System.out.println("not a Perfect number");
break;
}
}
}

113
114
BIBLIOGRAPHY

For completion of this project file our subject teacher of computer applications
Mr.Asif Ismail have given us constant support and guidance throughout.
I have used:
Touchpad computer applications class 10 ICSE book

SAMRIDHI GUPTA
10th -B

115

You might also like