0% found this document useful (0 votes)
153 views52 pages

Xii-Icse: Computer Project

This document contains a certificate certifying that Aditya Nautiyal, a Class X student, completed a computer project under the guidance of his teacher Mr. Sachin Gairoli. The project followed ICSE syllabus guidelines. It also contains programs written in Java for various problems involving character classification, checking leap years, finding days of the week, determining triangle types, checking case of characters, and other numerical analyses. The programs demonstrate concepts like loops, conditional statements, methods and provide sample inputs and outputs.

Uploaded by

Addy Nautz
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)
153 views52 pages

Xii-Icse: Computer Project

This document contains a certificate certifying that Aditya Nautiyal, a Class X student, completed a computer project under the guidance of his teacher Mr. Sachin Gairoli. The project followed ICSE syllabus guidelines. It also contains programs written in Java for various problems involving character classification, checking leap years, finding days of the week, determining triangle types, checking case of characters, and other numerical analyses. The programs demonstrate concepts like loops, conditional statements, methods and provide sample inputs and outputs.

Uploaded by

Addy Nautz
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/ 52

2019-2020

XII-ICSE

Computer Project

MADE BY:
ADITYA NAUTIYAL
Certificate
This is to certify that Aditya Nautiyal of Class X has prepared
this project under guidance of Mr Sachin Gairola (Subject
Teacher). This project of Computers’ has been prepared
following the guideline within syllabus of ICSE.

Student’s Sign Teacher’s Sign


Program 6:Program that accepts a value from the user,and checks whether it is a character,digit or a
special character.
class Character
{
public static void main(char ch)
{
System.out.println(“Entered value”+ch);
If((ch>=’A’)&&(ch,=’Z’)||(ch>’a’)&&(ch<=’z’))
System.out.println(“Value”+ch+”is a character”);
else if((ch>=’0’&&ch<=’9’))
System.out.println(“Value”+ch+”is a digit”);
else
System.out.println(“Value”+ch+”is a special charater”);
}}
OUTPUT:
Entered value @
Value @ is a special character
Program 7: Program to check whether the entered year is a leap year or not
import java.util.*;
class LeapYear
public static void main(String args[])
{Scanner kb=new Scanner(System.in);
System.out.println(“enter the year”);
int y =kb.nextInt();
if(y%400==0)||((y%100!=0)&&(y%4==0)))
{System.out.println(“It is a leap year”);
}
else{System.out.println(“It is not a Leap Year”);
}
}}
OUTPUT:
enter the year
2012
It is a leap year

Program 8: Program to print corresponding days of the week


import java.util.*;
class week
{
public static void main(String args[])
{ Scanner kb=new Scanner(System.in);
int val;
System.out.println(“enter the day no.”);
val=kb.nextInt();
if(val==1}
System.out.println(“Monday”);
else if(val==2)
System.out.println(“Tueaday”);
else if(val==3)
System.out.println(“Wednesday”);
else if(val==4)
System.out.println(“Thursday”);
else if(val==5)
System.out.println(“Friday”);
else if(val==6)
System.out.println(“Saturday”);
else if(val==7)
System.out.println(“Sunday”);
else
System.out.println(“invalid option);
}}
OUTPUT:
enter the day no.
5
Friday

Program 10: To print digit entered by user in words


1 ->one
import java.util.*; // importing util package
class string1
{
public static void main(String s[])
{Scanner k=new Scanner(System.in); // creating new object of Scanner class
System.out.println("enter a digit");
int num=k.nextInt(); // storing value entered by user
int disp =” ”;
switch(num)
{
case 1: System.out.println(“One”); // if no. is 1 then printing one
case 2: System.out.println(“Two”); // if no. is 2 then printing two
case 3: System.out.println(“Three”); // if no. is 3 then printing three
case 4: System.out.println(“Four”); // if no. is 4 then printing four
case 5: System.out.println(“Five”); // if no. is 5 then printing five
case 6: System.out.println(“Six”); // if no. is 6 then printing six
case 7: System.out.println(“Seven”); // if no. is 7 then printing seven
case 8: System.out.println(“Eight”); // if no. is 8 then printing eight
case 9: System.out.println(“Nine”); // if no. is 9 then printing Nine
case 0: System.out.println(“zero”); // if no. is 0 then printing zero
default: System.out.println(“Invalid input, please enter one digit number”);
}}}
OUTPUT:
enter a digit
1
One

Program 13: Program to determine whether a triangle is scalene ,isosceles or equilateral


import java.util.*;
class triangle
{public static void main(String s[])
{Scanner sc = new Scanner(System.in);
System.out.println("Enter sides of the triangle");
int s1=sc.nextInt(); //side of triangle
int s2=sc.nextInt(); //side of triangle
int s3=sc.nextInt(); //side of triangle
if(s1==s2&&s1==s3) //for equilateral triangle
{System.out.println("it is an equilateral triangle");}
else if(s1==s2||s1==s3||s2==s3) //for isosceles triangle
{System.out.println("it is an isoceles triangle");}
else //for scalene triangle
{System.out.println("it is scalene triangle");}
}
}
OUPUT:
Enter sides of the triangle
1
2
3
it is scalene triangle
Enter sides of the triangle
1
2
1
it is an isoceles triangle
Enter sides of the triangle
2
2
2
it is an equilateral triangle

PROGRAM 14:Program to check if character is uppercase,lowercase or special character


import java.util.*;
class charTest
{
public static void main(String s[])
{
Scanner k=new Scanner(System.in);
System.out.println("enter a character");
char ch=k.next().charAt(0);
if(ch>='A'&&ch<='Z')
System.out.println("it is an upper case alphabet");
else if(ch>='a'&&ch<='z')
System.out.println("it is a lower case alphabet");
else
System.out.println("it is a special character");
}
}
OUTPUT:
enter a character
A
it is an upper case alphabet

PROGRAM 15:Program to get no. of days in month


import java.util.*;
class Switch
{
public static void main(String s[])
{
Scanner k=new Scanner(System.in);
System.out.println("enter month number");
int n=k.nextInt();
switch(n)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
System.out.println("it has 31 days");break;
case 4:
case 6:
case 9:
case 11:
System.out.println("it has 30 days");break;
case 2:
System.out.println("it has 28 days");break;
}
}
}
OUTPUT:
enter month number
6
it has 30 days

Program 18:to print Fibonacci series


class fibonacci
{
public static void main(String s[])
{
int a=0;
int b=1;int c;
System.out.print("0 1 ");
for(int i=0;i<10;i++)
{
c=a+b; //adding last two terms
System.out.print(c+" ");
b=c; //assigning next value
a=b; //assigning next value
}
}
}
OUTPUT:
0 1 1 2 4 8 16 32 64 128 256 512
Program 19:to check whether a number is twisted prime or not
Program 13 is prime as well as its reverse 31
import java.util.*;
class twisted_prime
{
public static void main(String s[])
{
Scanner k=new Scanner(System.in);
System.out.println("enter a number");
int num=k.nextInt();
int sum=0;int count=0;
for(int i=1;i<num;i++) //checking prime
{
if(num%i==0)
count++;
}
if(count!=1)
{
System.out.println("no it is not prime");
return;
}
count=0;
while(num>0) //reversing
{
int rem=num%10;
sum=sum+rem;
num=num/10;
}
for(int i=1;i<sum;i++) //checking prime
{
if(sum%i==0)
count++;
}
if(count==1)
{
System.out.println("it is twisted prime");
}
else
{
System.out.println("no it is not twisted prime");
}
}
}
OUTPUT:
enter a number
19
No it is not twisted prime
enter a number
13
yes it is twisted prime

Program 20:to print series:0 3 8 15 24 35 48 63 80 99


class serie1
{
public static void main(String s[])
{
for(int i=1;i<11;i++)
{
System.out.print(i*i-1+" ");
}
}
}
OUTPUT:
0 3 8 15 24 35 48 63 80 99

Program 21:to check whether a number is neon or not


Ex:a number is neon if sum of its digits is divisible by 10
import java.util.*;
class neon
{
public static void main(String s[])
{
Scanner k=new Scanner(System.in);
System.out.println("enter a number");
int num=k.nextInt();
int sum=0;
while(num>0)
{
int rem=num%10;
sum=sum+rem; //adding digits
num=num/10;
}
if(sum%10==0) //checking divisiblity
{
System.out.println("neon number");
}
else
{
System.out.println("no it is not a neon number");
}
}
}
OUTPUT:
enter a number
991911
neon number
enter a number
32
No it is not a neon number

Program 22:to check whether entered number is prime or not


import java.util.*;
class prime
{
public static void main(String s[])
{
Scanner k=new Scanner(System.in);
System.out.println("enter a number");
int num=k.nextInt();
int count=0;
for(int i=1;i<num;i++) //checking prime
{
if(num%i==0)
count++;
}
if(count==1)
{
System.out.println("it is a prime number");
}
else
{
System.out.println(“no it is not a prime number”);
}
}
OUTPUT:
enter a number
37
it is a prime number
enter a number
9
no it is a prime number

Program 23:to check whether entered number is special or not


A number is special if sum of factorial of its digit is equal to the number
import java.util.*;
class s_num
{
public static void main(String s[])
{
Scanner k= new Scanner(System.in);
System.out.println("enter number");
int n=k.nextInt();
int num=n;int sum=0;
while(n>0) //checking it is special number or not
{
int rem=n%10;
int fact=1;
for(int i=1;i<=rem;i++)
{
fact=fact*i;
}
sum=sum+fact;
n=n/10;
}
if(sum==num)
{
System.out.println("it is special number");;
}
else
{
System.out.println("not a special number");
}
}
}
OUTPUT:
enter number
6
Not a special number

Program 24:to find whether a number is palindrome or not


A number is palindrome if it is same when it is read from either side eg-121
import java.util.*;
class palindrome
{
public static void main(String s[])
{
Scanner k= new Scanner(System.in);
System.out.println("enter number");
int n=k.nextInt();
int num=n;int sum=0;
while(n>0) //reversing number
{
int rem=n%10;
sum=sum*10+rem;
n=n/10;
}
if(sum==num) //checking its equality
{
System.out.println("it is palindrome");
}
else
{
System.out.println("no");
}
}
}
OUTPUT:
enter number
1331
it is palindrome

Program 25:to print sum of digits of a number


import java.util.*;
class digitSum
{
public static void main(String s[])
{
Scanner k= new Scanner(System.in);
System.out.println("enter number");
int n=k.nextInt();
int sum=0;
while(n>0) //calculating sum of digits
{
int rem=n%10;
sum=sum+rem;
n=n/10;
}
System.out.println("sum of digits is"+sum);
}
}
OUTPUT:
enter number
12345
sum of digits is15

PROGRAM 26:to create a program as per the following instructions


Class variables
Ename-for employee name
Eid-for employee id
Salary-for basic salary
Tax-for income tax
Net-total salary
Pan-for pan number
Member methods
Void input to enter details
Void cal to calculate income tax and net salary
Void display to display details
Write a main method to call these functions
import java.util.*;
class Emp_Tax
{
Scanner k=new Scanner(System.in);
String ename,eid;
double salary,tax,net;
long pan;
void input() //to enter details
{System.out.println("enter name,id,salary,pan");
ename=k.nextLine();
eid=k.nextLine();
salary=k.nextDouble();
pan=k.nextLong();}
void cal() //to calculate tax
{
if(salary<=200000)
{tax=0;}
else if(salary<500000)
{tax=10/100*salary;}
else if(salary<1000000)
{tax=20/100*salary;}
else
{tax=30/100*salary;}
net=salary-tax;
}
void display() //to display
{
System.out.println(ename+" pan no. "+pan+" salary "+salary+" tax "+tax+" net "+net);
}
public static void main(String s[])
{
Emp_Tax ob=new Emp_Tax();
ob.input();
ob.cal();
ob.display();
}
}
OUTPUT:
enter name,id,salary,pan
Aditya
98766
546666666
08778576576764
Aditya pan no 8778576576764 salary 5.46666666E8 tax 0.0 net 5.46666666E8

Program 27:to demonstrate methods of math class


class mathclass
{
public static void main(String s[])
{
System.out.println("absoulute valueof-23 "+Math.abs(-23));
System.out.println("minimum of 20,25 "+Math.min(20,25));
System.out.println("180 degree in radian is "+Math.toRadians(180));
System.out.println("exponent of e to 3 "+Math.exp(3));
System.out.println("cosine of 45 "+Math.cos(45));
System.out.println("random between 0,1 "+Math.random());
}
}
OUTPUT:
absoulute valueof-23 23
minimum of 20,25 20
180 degree in radian is 3.141592653589793
exponent of e to 3 20.085536923187668
cosine of 45 0.5253219888177297
random between 0,1 0.21413701692270104

Program 28:to demonstrate function overloading


class fnoverload
{
double area(double r) //area of circle
{double ar=22/7*r*r;
return ar;}
double area(int l,int b) //area of rectangle
{double ar=l*b;
return ar;}
double area(int s) //area of square
{double ar=s*s;
return ar;}
public static void main(String s[])
{
fnoverload ob1=new fnoverload();
fnoverload ob2=new fnoverload();
fnoverload ob3=new fnoverload();
System.out.println("area of circle is "+ob1.area(8.9));
System.out.println("area of rectangle is "+ob2.area(8,9));
System.out.println("area of sqare is "+ob3.area(7));
}}
OUTPUT:
area of circle is 237.63000000000002
area of rectangle is 72.0
area of sqare is 49.0
Program 29:to demonstrate woking of function by creating two functions that will display different
messages and call them one by one in main method
class func
{
void Function1 ()
{System.out.println(“this statement is in function 1”);
System.out.println(“exiting function 1……”);
void Function2 ()
{ System.out.println(“this statement is in function 2”);
System.out.println(“exiting function 2……”);
}
public static void main(String args[])
{ func cob=new func();
System.out.println(“This statement is in main function”);
ob.Function1 ();
ob.Function2 ();
}}
OUTPUT:
This statement is in main function
this statement is in function 1
exiting function 1……
this statement is in function 2
exiting function 2……

Program 30:Program that will add 10% tax to the bill amount
class clb
{public void AddTax(int billamo)
{billamo=billamo+(billamo*10/100);
System.out.println(“total bill amount after adding tax is: “ +billamo);
}
public static void main(String args[])
{
clb ob=new clb();
int billmo=1200;
System.out.println(“Basic bill amount is:” +billmo);
ob.addtax(biilmo);
}}
OUTPUT:
Basic bill amount is:1200
total bill amount after adding tax is:1320

PROGRAM :to define a class sphere as per the following instructions


Class name: sphere
Instance variables: radius,double type
Member methods:
sphere(double r) constructor to assign value to radius
double calcVol()method to return volume of the sphere
double surfaceArea() method to return surface area of sphere
double volHemisphere() method to return the volume of the hemisphere
import java.util.*;
class sphere
{double radius;
sphere(double r)
{radius=r;}
double calcVol()
{return 4*Math.PI*radius*radius*radius/3;}
double surfaceArea()
{return 4*Math.PI*radius*radius;}
double volHemisphere()
{return calcVol()/2;}
public static void main(String s[])
{
Scanner k=new Scanner(System.in);
System.out.println("enter radius");
double r=k.nextDouble();
sphere ob=new sphere(r);
System.out.println(ob.calcVol());
System.out.println(ob.surfaceArea());
System.out.println(ob.volHemisphere());
}
}
OUTPUT:
enter radius
7
1436.7550402417319
615.7521601035994
718.3775201208659OUTPUT:
I am inside default constructor...

Program 32:Demonstrate use of parameterized constructor


public class MyParameterizedConstructor
{
private String name;
public MyParameterizedConstructor(String str){
this.name = str;
System.out.println("I am inside parameterized constructor.");
System.out.println("The parameter value is: "+str);
}
public static void main(String a[]){
MyParameterizedConstructor mpc = new MyParameterizedConstructor("Aditya Nautiyal");
}
}
OUTPUT:
I am inside parameterized constructor
The parameter value is: Aditya Nautiyal

Program 33:Test Constructor


public class Test
{
public Test()
{
System.out.printf("1");
new Test(10);
System.out.printf("5");
}
public Test(int temp)
{
System.out.printf("2");
new Test(10, 20);
System.out.printf("4");
}
public Test(int data, int temp)
{
System.out.printf("3");

}
public static void main(String[] args)
{
Test obj = new Test();
}}
OUTPUT:
12345

PROGRAM 34:to demonstrate constructor overloading


class cube
{
int length,breadth,height;
cube() //constructor to initialize all data members
{
length=10;
breadth=10;
height=10;
}
cube(int l,int b) //parameterized constructor
{
length=l;
breadth=b;
height=10;
}
cube(int l,int b,int h) //parameterized constructor
{
length=l;
breadth=b;
height=h;
}
int vol() //to return volume
{
return(length*breadth*height);
}
public static void main(String s[])
{
cube ob1=new cube();
cube ob2=new cube(11,11);
cube ob3=new cube(11,11,11);
System.out.println("Volume of cube1 "+ob1.vol());
System.out.println("Volume of cube2 "+ob2.vol());
System.out.println("Volume of cube3 "+ob3.vol());
}
}
OUTPUT:
Volume of cube1 1000
Volume of cube2 1210
Volume of cube3 1331

PROGRAM 35:to calculate the loss or profit percent


import java.util.*;
class shopkeeper
{
public static void main(String args[])
{
Scanner k=new Scanner(System.in);
System.out.println("enter c.p. and s.p.");
int c=k.nextInt();
int s=k.nextInt();
if(s>c) //checking profit or loss
{int p=s-c;
double pp=(p*100)/c;
System.out.print("you have"+pp+"% profit");
}
else if(c>s)
{int l=c-s;
double lp=(l*100)/c;
System.out.print("you have"+lp+"% loss");
}
else
{
System.out.print("you have neither profit nor loss");}
}
}OUTPUT:
enter c.p. and s.p.
100
150
you have50.0% profit

PROGRAM 36:to convert temperature from Celsius to Fahrenheit and vice versa
import java.util.*;
class temperature
{
public static void main(String s[])
{
Scanner k=new Scanner(System.in);
System.out.print("enter choice 1 for C to F and 2 for F to C");
int ch=k.nextInt();
System.out.println("enter temperature");
double t=k.nextDouble();
switch(ch) //choice
{
case 1: //fahrenheit
double f=(9*t)/5+32;
System.out.print(f);
break;
case 2: //celsius
double c=(5*t-160)/9;
System.out.print(c);
break;
}
}
}
OUTPUT:
enter choice 1 for C to F and 2 for F to C
2
enter temperature
108
42.22222222222222

PROGRAM 37:to check whether number is Armstrong


A number is Armstrong if sum of cube of its digits is equal to the number itself
import java.util.*;
class armstrong
{
public static void main(String s[])
{
Scanner k= new Scanner(System.in);
System.out.println("enter number");
int n=k.nextInt();
int num=n;int sum=0;
while(n>0) //checking if its Armstrong or not
{
int rem=n%10;
sum=sum+rem*rem*rem;
n=n/10;
}
if(sum==num)
{
System.out.println("it is armstrong");
}
else
{
System.out.println("no it is not armstrong ");
}
}
}
OUTPUT:
enter number
135
it is armstrong

PROGRAM 38:to display ascii of any character


import java.util.*;
class ascii
{
public static void main(String s[])
{
Scanner k=new Scanner(System.in);
System.out.println("enter a character");
char ch=(k.next()).charAt(0);
int asciicode=ch; //storing asciicode
System.out.print(asciicode);
}
}
OUTPUT:
enter a character
a
97

PROGRAM 39:to find the nature of the roots of a quadratic equation


import java.util.*;
class quadRoots
{
public static void main(String s[])
{
Scanner k=new Scanner(System.in);
System.out.println("enter the value of a,b and c in the equation");
int a=k.nextInt();
int b=k.nextInt();
int c=k.nextInt();
int d=b*b-4*a*c;//calculating nature of roots using formulae d=b*b-4ac
String ans=(d==0)?"real and equal":((d<0)?"not real":"real and unequal");
System.out.print(ans);
}
}
Output:
enter the value of a,b and c in the equation
5
9
8
not real

PROGRAM 40 :to print factorial of a number


import java.util.*;
class Fact
{
static int num;
Fact() //default constructor
{num=0;}
public static int data() //inputing data
{Scanner k=new Scanner(System.in);
System.out.print("enter a number");
int num1=k.nextInt();
return num1;
}
public static void factorial(int x) //calculating factorial
{
int fact=1;num=x;
while(num>=1)
{fact=fact*num;
num--;
}
System.out.println("factorial is "+fact);
}
public static void main() //creating object
{int a=Fact.data();
Fact.factorial(a);
}
}
OUTPUT:
enter a number4
factorial is 24

PROGRAM 41:to sort a string array using bubble sorting technique


import java.util.*;
class strsort
{
public static void main(String s[])
{
Scanner k=new Scanner(System.in);
System.out.println("enter no. of names");
int n=k.nextInt();
String arr[]=new String[n];
System.out.println("enter names");
for(int i=0;i<n;i++) //sorting strings
{arr[i]=k.nextLine();}
for(int i=0;i<n;i++)
{
for(int j=0;j<n-1-i;j++)
{int flag=arr[j].compareTo(arr[j+1]); //returns Boolean value
if(flag>0)
{String t=arr[j];
arr[j]=arr[j+1];
arr[j+1]=t;
}
}
}
for(int i=0;i<n;i++)
System.out.print(arr[i]+" ");
}
}
OUTPUT:
enter no. of names
3
enter names
adi
pra
oja
adi oja pra

PROGRAM 42:to merge two given arrays in a single array


import java.util.*;
class merge1
{
public static void main(String s[])
{
int a[]=new int[5];
int b[]=new int[5];
int c[]=new int[10];
Scanner k=new Scanner(System.in);
System.out.println("enter 5 numbers in each array");
for(int i=0;i<5;i++)
a[i]=k.nextInt();
for(int i=0;i<5;i++)
b[i]=k.nextInt();
int d=0; //for location of final array
for(int i=0;i<5;i++)
{c[d]=a[i];d++;}
for(int i=0;i<5;i++)
{c[d]=b[i];d++;}
for(int i=0;i<10;i++)
System.out.print(c[i]+" ");
}
}
OUTPUT:
enter 5 numbers in each array
12345
23456
34567
45678
56789
67890
78901
89012
90123
01234
12345 23456 34567 45678 56789 67890 78901 89012 90123 1234

PROGRAM 43:to demonstrate bubble sorting technique using numbers


import java.util.*;
class bsort1
{
public static void main(String s[])
{
Scanner k=new Scanner(System.in);
System.out.println("enter the length of array");
int n=k.nextInt();
int arr[]=new int[n];
System.out.println("enter numbers");
for(int i=0;i<n;i++) //input numbers
arr[i]=k.nextInt();
for(int i=0;i<n;i++) //number of time it will run
{
for(int j=0;j<n-1-i;j++) //for shifting greatest element at last
{if(arr[j]>arr[j+1])
{int t=arr[j];
arr[j]=arr[j+1];
arr[j+1]=t;}
}}
for(int i=0;i<n;i++)
System.out.print(arr[i]+" ");
}}
OUTPUT:
enter the length of array
10
enter numbers
9
8
7
6
5
4
3
2
78
90
2 3 4 5 6 7 8 9 78 90

PROGRAM 44:to demonstrate selection sorting technique


import java.util.*;
class ssort
{
public static void main(String s[])
{
Scanner k=new Scanner(System.in);
System.out.println("enter the length of array");
int n=k.nextInt();
int arr[]=new int[n];
System.out.println("enter numbers");
for(int i=0;i<n;i++)
arr[i]=k.nextInt();
int pos=0;
for(int i=0;i<n;i++) //number of elements
{pos=i;
for(int j=i+1;j<n;j++) //smallest element
{if(arr[pos]>arr[j])
pos=j;
}
int t=arr[i];
arr[i]=arr[pos];
arr[pos]=t;
}
for(int i=0;i<n;i++)
System.out.print(arr[i]+" ");
}
}}
OUTPUT:
enter the length of array
5
enter numbers
25
36
75
8
12
8 12 25 36 75

PROGRAM 45: to sort array using methods


import java.util.*;
class armethod
{
int n;
int a[];
void input()
{
Scanner k=new Scanner(System.in);
System.out.println("enter length of array");
n=k.nextInt();
int a[]=new int[n];
System.out.println("enter numbers");
for(int i=0;i<n;i++)
a[i]=k.nextInt();
}
void sort()
{
for(int i=0;i<n;i++)
for(int j=0;j<n-1-i;j++)
{if(a[j]>a[j+1])
{int t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}}}
void display()
{
System.out.println("the sorted array is");
for(int i=0;i<n;i++)
System.out.print(a[i]+" ");
}
public static void main(String s[])
{
armethod ob=new armethod();
ob.input();
ob.sort();
ob.display();
}}
OUTPUT:
enter length of array
3
enter number
1
4
3
the sorted array is
134
PROGRAM 46:to arrange all number in array with negative first positive last without changing their
order
import java.util.*;
class array
{
public static void main(String s[])
{
Scanner k=new Scanner(System.in);
System.out.println("enter length of array");
int n=k.nextInt();
int a[]=new int [n];
System.out.println("enter numbers");
for(int i=0;i<n;i++)
a[i]=k.nextInt();
int f=0,r=1;
while(r<n)
{if(a[r]<0)
{int t=a[r];
a[r]=a[f];
a[f]=t;
f++;}
r++;
}
for(int i=0;i<n;i++)
System.out.print(a[i]+" ");
}
}
OUTPUT:
enter length of array
5
enter numbers
12
-9
-7
7
-6
-9 -7 -6 7 12

PROGRAM 47:to search a string in an array


import java.util.*;
class strsearch
{
public static void main(String s[])
{
Scanner k=new Scanner(System.in);
System.out.println("enter no of people");
int n=k.nextInt();
long no[]=new long[n]; //for storing numbers
String name[]=new String[n]; //for storing names
for(int i=0;i<n;i++) //entering values
{System.out.println("enter name and number");
name[i]=k.nextLine();
no[i]=k.nextLong();
}
System.out.println("enter name whose number is to be searched");
String sc=k.nextLine(); //to be searched
int l=0;
for(int i=0;i<n;i++)
{if(name[i]==sc)
{System.out.println(name[i]+" "+no[i]);l++;}
}
if(l!=0)
{System.out.print("not found");}}
}
OUTPUT:
enter no of people
3
enter name and number
anant
2310
enter name and number
mayank
3010
enter name and number
aditya
2010
enter name whose number is to be searched
mudit
not found
PROGRAM 48:to store name and number of n number of people and search entered name
import java.util.*;
class pbook
{
public static void main(String s[])
{
Scanner k=new Scanner(System.in);
System.out.println("enter no of people");
int n=k.nextInt();
long no[]=new long[n];//array for storing numbers
String name[]=new String[n];//array for storing names
for(int i=0;i<n;i++)//loop for entering details
{System.out.println("enter name and number");
name[i]=k.nextLine();
no[i]=k.nextLong();
}
for(int i=0;i<n;i++)//sorting list alphabetically
{
for(int j=0;j<n-1-i;j++)
{int r=name[j].compareTo(name[j+1]);
if(r>1)
{String t=name[j];
name[j]=name[j+1];
name[j+1]=t;
long temp=no[j];
no[j]=no[j+1];
no[j+1]=temp;
}
}
}
for(int i=0;i<n;i++)//displaying list
{System.out.println(name[i]+" "+no[i]);}
}
}
OUTPUT:
enter no of people
2
enter name and number
aditya
9412007372
enter name and number
rahul
6757575757
aditya 9412007563
rahul 6757575757

Program 49: to print row and column with array and printing highest value from them
public class arr10
{ public static void main()
{ String n[]={"A","B","C","D","E"};
int p[]={10, 15, 18, 12, 25};
int c[]={20, 15, 22, 23, 12};
int m[]={25, 25, 20, 10, 18};
int h=0;
String s="";
for(int i=0; i<n.length; i++)
{ int t=p[i]+c[i]+m[i];
if(t>h)
{ h=t;
s=n[i];
}
System.out.println(n[i]+" "+p[i]+" "+c[i]+" "+m[i]+" "+t);
}
System.out.println("Highest= "+h+" of "+s);
}
}
OUTPUT:
A 10 20 25 55
B 15 15 25 55
C 18 22 20 60
D 12 23 10 45
E 25 12 18 55
Highest= 60 of C

Program 50:Checking an array is a palindrome array or not


public class Q07
{ public static void main()
{ int org[]={1,2,3,2,1};
int rev[]=new int[org.length];
int end=org.length-1;
for(int i=0; i<rev.length; i++)
{ rev[i]=org[end];
end--;
}
int count=0;
for(int i=0; i<org.length; i++)
{ if(rev[i]==org[i])
{ count++;
}}
if(count==org.length)
System.out.println("Palindrome array");
else
System.out.println("Not a Palindrome array");
}}
OUTPUT:
Palindrome array

PROGRAM 51: To print each digit of number in words


10345 ->one zero three four five
import java.util.*; // importing util package
class string1
{
public static void main(String s[])
{Scanner k=new Scanner(System.in); // creating new object of Scanner class
System.out.println("enter a number");
int num=k.nextInt(); // storing value entered by user
String disp="";
while(num>0)
{int rem=num%10; // Separating each digit
switch(rem)
{
case 1: // if no. is 1 then printing one
disp="one "+disp;
break;
case 2: // if no. is 2 then printing two and so on…
disp="two "+disp;
break;
case 3:
disp="three "+disp;
break;
case 4:
disp="four "+disp;p
break;
case 5:
disp="five "+disp;
break;
case 6:
disp="six "+disp;
break;
case 7:
disp="seven "+disp;
break;
case 8:
disp="eight "+disp;
break;
case 9:
disp="nine "+disp;
break;
case 0:
disp="zero "+disp;
break;
}
num=num/10; // to change to next no.
}
System.out.print(disp);
}
}
OUTPUT:
enter a number
10345
one zero three four five

PROGRAM 52:to store vowels of a string at the end and consonants in the beginning without changing its
order
import java.util.*; // importing util package
class string2
{
public static void main(String s[])
{
Scanner k=new Scanner(System.in); // creating object of Scanner class
System.out.println("enter a word");
String str=kb..nextLine(); // storing string entered by user

String s1="";
String s2="";
for(int i=0;i<str.length();i++)
{
char ch=str.charAt(i);
if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u'||ch=='A'||ch=='E'||ch=='I'||ch=='O'||ch=='U') // arranging vowel
s1=s1+ch;
else
s2=s2+ch; // arranging consonant
}
String str1=s2+s1; //storing consonants first and vowels at last
System.out.print(str1);
}
}
OUTPUT:
enter a word
dehRAdUn
dhRdneAU

PROGRAM 53:TO PRINT


BLUEJ
LUEJB
UEJBL
EJBLU
JBLUE
class String3
{
public static void main(String s[])
{
String str="BLUEJ";
for(int i=0;i<5;i++) // for loop to print in the given pattern
{
System.out.print(str.substring(i));
System.out.println(str.substring(0,i));
}
}}
OUTPUT:
BLUEJ
LUEJB
UEJBL
EJBLU
JBLUE

PROGRAM 55:to print first name in a three word name at last


import java.util.*; // importing util package
class string5
{
public static void main(String args[])
{
Scanner k=new Scanner(System.in); // creating object of Scanner class
System.out.println("enter a 3 word name");
String s=k.nextLine();
int i;
for(i=0;i<s.length();i++)
{
if(s.charAt(i)==' ') //finding space
{System.out.print(s.substring(i)+” “);
break;}
}
System.out.print(s.substring(0,i));
}
}
OUTPUT:
enter a 3 word name
amey pakash sati
prakash sati amey

PROGRAM 58:to print initials of the name


import java.util.*;

class string8
{
public static void main(String s[])
{
Scanner kb=new Scanner(System.in);
System.out.println("enter a 3 word name");
String str=kb.nextLine();//storing name
str=str+" ";
String s1="";
s1=s1+str.charAt(0);int c=0;
for(int i=1;i<str.length();i++)
{if(str.charAt(i)==' ')//finding space
{c++;
if(c==1)
{s1=s1+"."+str.charAt(i+1)+".";}//storing second initial
else
{s1=s1+str.substring(i+1);break;}//storing last word
}
}
System.out.print(s1);
}
}
OUTPUT:
enter a 3 word name
Amey Prakash Sati
A.P.Sati

PROGRAM 59:to change each vowel with next vowel an each digit with next digit
import java.util.*;
class string9
{
public static void main(String s[])
{
Scanner kb=new Scanner(System.in);
System.out.println("enter a string");
String str=kb.nextLine();
String sc="aeiou0123456789";
String ch="eioua1234567890";
String disp="";
str=str.toLowerCase();
for(int i=0;i<str.length();i++)
{int j=sc.indexOf(str.charAt(i));
if(j>=0) //checking if we have it in sc
{disp=disp+ch.charAt(j);} //changing character
else
{disp=disp+str.charAt(i);}
}
System.out.println(disp);
}
}
OUTPUT:
enter a string
name Aditya roll no. 12
nemi edotye rull nu. 23

PROGRAM 60:to print each word’s first letter in capital


import java.util.*;
class string10
{
public static void main(String s[])
{
Scanner k=new Scanner(System.in);
System.out.println("enter a string");
String str=k.nextLine();
String s1="";
str=str.toLowerCase();
char ch,ch1;
str=" "+str;
for(int i=0;i<str.length();i++)
{
ch=str.charAt(i);
if(ch==' ') //for finding beginning of the word
{ch1=str.charAt(i+1);
s1=s1+' '+Character.toUpperCase(ch1); //converting it to upper case
i=i+1;}
else
{s1=s1+ch;}
}
System.out.println("new string= "+s1);
}
}
OUTPUT:
enter a string
my name is aditya
new string= My Name Is Aditya

You might also like