0% found this document useful (0 votes)
92 views36 pages

Class10 Project

This document contains 21 computer programs written by Armaan Singh on June 7, 2019 for Shiwalik International School. The programs cover a range of concepts including loops, arrays, methods, functions, string manipulation, pattern printing, and mathematical operations. Examples include programs to find the value of t, print tables, use mathematical functions, arrange arrays in ascending order, print alphabet patterns, reverse case of strings, check string functions, calculate sums based on user input, count characters in strings, calculate series sums, print patterns, find array sums, check for "duck numbers", calculate expressions, find factorials, calculate volumes using overloading, find greatest numbers, calculate greatest common divisors, calculate interest, and find maximum and minimum

Uploaded by

Ashish Grover
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)
92 views36 pages

Class10 Project

This document contains 21 computer programs written by Armaan Singh on June 7, 2019 for Shiwalik International School. The programs cover a range of concepts including loops, arrays, methods, functions, string manipulation, pattern printing, and mathematical operations. Examples include programs to find the value of t, print tables, use mathematical functions, arrange arrays in ascending order, print alphabet patterns, reverse case of strings, check string functions, calculate sums based on user input, count characters in strings, calculate series sums, print patterns, find array sums, check for "duck numbers", calculate expressions, find factorials, calculate volumes using overloading, find greatest numbers, calculate greatest common divisors, calculate interest, and find maximum and minimum

Uploaded by

Ashish Grover
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/ 36

SHIWALIK INTERNATIONAL SCHOOL

COMPUTER APPLICATION
COMPUTER PROGRAMS
ARMAAN SINGH
7/6/2019
1. W.A.P to find the vale of t.
import java.io.*;
public class A
{
public static void main(String args [])
{
int sum=0,score=0;
double t;
do
{
score=score+1;
sum=sum+score;
}while(score<=3);
t=sum/3;

System.out.println("The value of t is : "+t);


}
}
1. W.A.P to print the tables of 2,3,4
public class aaa
{
public static void main(String args[])
{
int i,j;
for(i=2;i<=4;i++)
{
for(j=1;j<=10;j++)
{
System.out.println(i+" * " + j+" = " +(i*j) + " ");
}
System.out.println(" ");
}
}
}
3.A program to show the use of Mathematical functions
import java .io.*;
import java.lang.*;
class abc
{
public static void main (String args[ ] )
{
double m=-6.25;
double n=8.75;
System.out.println("The output of diff mathematical func are");
System.out.println("Sqrt of 6.25 "+Math.sqrt(m));
System.out.println("Min value between 6.25 and 8.75= "+Math.min(m,n));
System.out.println("Max value between 6.25 and 8.75= "+Math.max(m,n));
System.out.println("6.25 raised to the power 3 =" +Math.pow (m,3));
System.out.println(" natural log of 6.25 ="+Math.log (m));
System.out.println ("absolute value of (6.25-8.25)= "+(float) Math.abs(m-n));
System.out.println("rounded value of 6.25= "+Math.round (m));
System.out.println("the floor of 6.25= "+Math.floor(m));
System.out.println("the ceil value of 6.25= "+Math.ceil(m));
System.out.println("truncated value of 6.25= "+Math.rint(m));
System.out.println("exponent value of 6.2= "+Math.exp(m));
}}
4.To arrange the value of array in ascending order

import java.io.*;
public class acending
{
public static void main(String args[])throws IOException
{
InputStreamReader read= new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(read);
int a,b,c,i,j,t,min;
int m[ ] = new int[10];
for( i=0;i<10;i++)
{
System.out.println("Enter the number in the cell");
m[i]= Integer.parseInt(in.readLine());
}
for(i=0;i<9;i++)
{
min=i;
for(j=i+1;j<10;j++)
{
if(m[j]<m[min])
min=j;
}
t=m[i];
m[i]=m[min];
m[min]=t;
}
System.out.println("The numbers are arranged in ascending order as");
for(i=0;i<10;i++)
System.out.println(m[i]);
}
}
5.Program to print pattern of alphabets

public class asd


{
public static void main(String args[])
{
int i,j;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
System.out.print((char)(64+i)+" ");
}
System.out.println(" ");
}
}
}
6. W.A.P to reverse the case of each alphabet of given string.

import java.io.*;
public class Change
{
public static void main(String args[])throws IOException
{
InputStreamReader read= new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(read);
String name,name1; name1=" ";
char chr,chr1; chr1=' ';
int a,i;
System.out.println("Enter your word");
name=in.readLine();
a=name.length();
for(i=0;i<a;i++)
{
chr=name.charAt(i);
if(chr>='A' && chr<='Z')
{
chr1=Character.toLowerCase(chr);
name1=name1+chr1;
}
else
{
if(chr>='a' && chr<='z')
{
chr1=Character.toUpperCase(chr);
name1= name1+chr1;

}
else
name1= name1+chr;
}
}
System.out.println(name1);
}
}
7. W.A.P to check the working of String function.
import java.io.*;
public class check
{
public static void main(String args[])
{
String x= "computer";
String y= "Applications";
System.out.println(y+x.substring(5));
System.out.println("Four"+(2+2));
char ch = "computer".charAt(3);
System.out.println(ch+" ");
}
}
8. Program to print the sum according to users choice.

import java.io.*;
public class choice
{
public static void main(String args[]) throws IOException
{
InputStreamReader read = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(read);
int n,y=0,a=0,b=0;
System.out.println("Enter a Positive or a Negative number");
n= Integer.parseInt(in.readLine());
if(n>0)
{
for(a=2;a<=1000;a++)
{
if (a%2==0)
{
y= y+a;
}
}
System.out.println("Sum of positive ="+y);
}
if(n<0)
{
for(a=-1000;a<0;a--)
{
if ( n%2==0)
{
b=b+n;
}
}
System.out.println("Sum of negative ="+b);
}
}
}
9. Program to count the number of spases words and alphabets in a string.

import java.io.*;
public class counting
{
public static void main(String args[])throws IOException
{
InputStreamReader read = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(read);
String name;
int a,i,b,w; b=0; w=0;
char chr;chr=0;
System.out.println("Enter your string");
name=in.readLine();
a=name.length();
for(i=0;i<a;i++)
{
chr=name.charAt(i);
if(chr==' ')
b=b+1;
}
w=b+1;
System.out.println("The no.of blanl spaces in the string is "+b);
System.out.println("The no.of words in the string is "+w);
System.out.println("The no. of alphabet in the string is "+(a-b));
}
}
10. Program to print the sum of the series
import java.io.*;
class cricket
{
public static void main (String args []) throws IOException
{
BufferedReader Br= new BufferedReader ( new InputStreamReader
(System.in));
int i,a,n;
double s=0;
System.out.println ("Enter the value of a and n");
a=Integer.parseInt(Br.readLine());
n=Integer.parseInt(Br.readLine());
for(i=1;i<n;i++);
s=s+(double) a/(i+1) ;
System.out.println(s+" sum of series is " );
}
}
11. Program to print the pattern
import java.io.*;
class cross
{
public static void main(String args[ ])
{
for (int i=1;i<=5;i++)
{
for(int k=5;k>i;k--)
System.out.print(" ");
for(int j=1;j<=i;j++)
System.out.print(j + " ");
System.out.println(" ");
}
}
}
12.Program to print the sum of the values of array.

public class ddsum


{
public static void main(String args[])
{
int i,j,s; s=0;
int m[ ][ ]={{3,4,5,6},{7,8,9,10},{11,12,13,14}};
for(i=0;i<3;i++)
{
for(j=0;j<4;j++)
{s=s+m[i][j];
}
}
System.out.println("The sum of the elements in the Matrix is :"+s);
}
}
13. Program to check wheather a number id duck number or not.

import java.util.*;
class duck
{
public static void main (String args[])
{
Scanner in =new Scanner(System.in);
int d, n,f=0;
System.out.println("enter a number");
n=in.nextInt();
while(n!=0)
{
d=n%10;
if(d==0)
{
f++;
}
n=n/10;
}
if (f!=0)
System.out.println("Duck No");
else
System.out.println("Not Duck No");
}
}
14. Program to find the value of given data

import java.io.*;

public class expression


{
public static void main(String []args) throws IOException
{
int a,b;
double p;
InputStreamReader read= new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(read);
System.out.println("Enter the value of a");
a= Integer.parseInt(in.readLine());
System.out.println("Enter the value of b");
b = Integer.parseInt(in.readLine());
p= Math.pow((a+b),3)/ (a-b);
System.out.println("The value of the expression ="+p);
}
}
15. Progra to find the factorial of the number.

class factorial
{
static int isfact (int x )
{
int f=1,i;
for (i=1;i<=x;i++)
f=f*i;
return (f);
}
public static void main(String args[])
{
int sb,n=5,m=8 ,pb;
sb= isfact (n);
pb= isfact (m);
System.out.println("the result is ="+sb);
System.out.println("the result is ="+pb);
}
}
16.To find the volume of a cube,a sphere and a cuboid using overloading

import java.util.*;
public class function
{
double vc=0,vs=0,vcd=0;
void volume(int s)
{
vc=s*s*s;
System.out.println("The volume of a cube ="+vc);
}
void volume(float r)
{
vs=(4/3)*(22/7)*r*r*r;
System.out.println("The volume of a sphere ="+vs);
}
void volume(int l,int b,int h)
{
vcd=l*b*h;
System.out.println("The volume of a cuboid ="+vcd);
}
public static void main(String args[ ])
{
Scanner in = new Scanner(System.in);
int a,b,c,d;
float k;
System.out.println("Enter the value of a,b,c,d and k");
a= in.nextInt();
b= in.nextInt();
c= in.nextInt();
d= in.nextInt() ;
k= in.nextFloat();
function ob= new function();
ob.volume(a);
ob.volume(k);
ob.volume(b,c,d);
}
}
17. Program to find the greatest number
public class greatest
{
public static void main(String args[])
{
int i,max=0;
int m[ ]={12,34,54,23,67,7,45,78,98,43};
for(i=0;i<10;i++)
{
if(max<m[i])
max=m[i];
}
System.out.println("The greatest number is "+max);
}
}
18 . To find GCD of two numbers

import java.io.*;
public class hcf
{
public static void main(String args[ ]) throws IOException
{
InputStreamReader read = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(read);
int n,m,i,p,h=0,l;
System.out.println("Enter two numbers");
m= Integer.parseInt(in.readLine());
n= Integer.parseInt(in.readLine());
p= m*n;
for(i=1;i<p;i++)
{
if(m%i==0 && n%i==0 )
{ h=i;
}
}
System.out.println("The GDC is = "+h);
}
}
19.

import java.io.*;
class interest
{
public static void main(String args[]) throws IOException
{
BufferedReader br= new BufferedReader (new InputStreamReader(System.in));
double i, p,a=0;
System.out.println("enter a sum");
p=Double.parseDouble(br.readLine());
i=p*0.05*1;
System.out.println("interest for first year "+i);
p=p+i;
i=p*0.05*1;
System.out.println("interest for second year "+i);
p=p+i;
i=0.05*p*1;
a=p+i;
System.out.println("amont after third year "+a);
}
}
20.

import java.io.*;
public class maxmin
{
public static void main(String args[]) throws IOException
{
InputStreamReader read = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(read);
int min,max,a,b,c;
System.out.println("Enter first number");
a= Integer.parseInt(in.readLine());
max=a; min=a;
for(b=1;b<=10;b++)
{
System.out.println("Enter you next nine choice");
c= Integer.parseInt(in.readLine());
if(min>c)
min=c;
if(max<c)
max=c;
}
System.out.println("The largest number is ="+max);
System.out.println("The smallest number id ="+min);
}
}
21. Find the maximum and minimum number.

import java.io.*;
public class maxmin1
{
public static void main(String args[])throws IOException
{
InputStreamReader read = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(read);
int max,min;
int m[ ]=new int[10];
for(int i=0;i<10;i++)
{
System.out.println("Enter the number in the cell");
m[i]= Integer.parseInt(in.readLine());
}
max=m[0]; min= m[0];
for(int a=0;a<10;a++)
{
if(max<m[a])
max=m[a];
if(min>m[a])
min=m[a];
}
System.out.println("The greatest number is "+max);
System.out.println("The lowest number is "+min);
}
}
22. Write a program to check wheather the number id palindrome or perfect
number according to user choice.

import java.io.*;
public class number
{
public static void main(String args[])throws IOException
{
InputStreamReader read= new InputStreamReader(System.in);
BufferedReader in= new BufferedReader(read);
int a,b,c,d,e=0,f=0;
System.out.println("Enter 1 to check a palindrome");
System.out.println("Enter 2 to check a perfect number");
a= Integer.parseInt(in.readLine());
switch(a)
{case 1:
System.out.println("Enter the number");
b= Integer.parseInt(in.readLine());
c=b;
do
{
d=b%10;
e=e*10+d;
b=b/10;
}while(b!=0);
if(e==c)
System.out.println("The number is Palindrome");
else
System.out.println("The number is not Palindrome");
break;
case 2:
System.out.println("Enter the number");
a= Integer.parseInt(in.readLine());
for(b=1;b<a;b++)
{if(a%b==0)
f=f+b;
}if(f==a)
System.out.println("The number is Perfect");
else
System.out.println("The Number is not Perfect");
break;
default:
System.out.println("It is a wrong choice");
}
}}
23. Pattern

import java.util.*;
class one
{
public static void main (String args[])
{
Scanner in =new Scanner (System.in);
int a,b;
String st;
System.out.println("enter your word to be print");
st=in.nextLine();
b=st.length();
for(a=b;a>=0;a--)
{
for(int i=0;i<a;i++)
{
System.out.print(st.charAt(i)+" ");
}
System.out.println(" ");
}
}
}
24. Pattern

import java.io.*;
public class patern
{
public static void main(String args[]) throws IOException
{
int a,b,p;
String st;
InputStreamReader read = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(read);
System.out.println("Enter the string");
st= in.readLine();
p= st.length();
for(a=0;a<=p;a++)
{
System.out.print(st.substring(a,p));
System.out.print(st.substring(0,a));
System.out.println();
}
}}
25. Pattern.

public class pattern1


{
public static void main(String args[])
{
int a,b, c;
for(a=1;a<=5;a++)
{
for(b=1;b<=a;b++)
{
System.out.print(b+" ");
}
System.out.println();
}
}
}
26.
public class pattern2
{
public static void main(String args[])
{
int a,b,c;
for(a=7;a>=1;a--)
{
for(b=1;b<=a;b++)
{
System.out.print(b+" ");
}
System.out.println();
}
}
}
27. Pattern

public class pattern3


{
public static void main(String args[])
{
int a,b,c,p=2;
for(a=1;a<=5;a++)
{
for(b=1;b<=a;b++)
System.out.print(a+" ");
for(c=p;c<=5;c++)
System.out.print(c+" ");
System.out.println();
p=p+1;
}
}
}
28. Programe to cheack wheather the number is prime or not.

import java.io.*;
public class Prime
{
public static void main(String args[]) throws IOException
{
InputStreamReader read = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(read);
int a,n,c=0;
System.out.println("Eneter the number");
n= Integer.parseInt(in.readLine());
for(a=2;a<=n;a++)
{
if(n%a==0)
{
System.out.println("Not a Prime Number");
break;
}

if(c==0)
{
System.out.println("Prime Number");
break;
}
}}}
29. Program to reverse the given string.

import java.io.*;
public class Reverse
{
public static void main(String args[])throws IOException
{
InputStreamReader read = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(read);
int i,j,d;j=0;
char k;
String m,p,t; p="";t="";
String n[]=new String[5];
System.out.println("Enter your word");
m=in.readLine();
d=m.length();
for(i=0;i<d;i++)
{k= m.charAt(i);
if(k!=' ')
t=t+k;
else
{
n[j]=t;
j=j+1;
t=" ";
}}
n[j]=t;
System.out.println("Your word displayed in reversed order is:");
for(i=j;i>=0;i--)
System.out.print(n[i]+" ");
}}
30. Program to search the number in the array.

import java.io.*;
public class search
{
public static void main(String args[])throws IOException
{
InputStreamReader read= new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(read);
int x,k=0;
int m[] = new int[10];
for(int i =0;i<10;i++)
{
System.out.println("Enter the number in the cell");
m[i]= Integer.parseInt(in.readLine());
}
System.out.println("Enter the number you want to find");
x= Integer.parseInt(in.readLine());
for(int a=0;a<10;a++)
{if(x==m[a])
k=1;
}
if(k==1)
System.out.println("The number "+x+" is present ");
else
System.out.println("Number is not present");
}}

You might also like