DAY 1:-
/*sorting means arranging an array either in ascending order or in descending order */
/*Sorting technique
There are two types of sorting technique
They are 1) Bubble sort 2) selection sort
Defination of selection sort- During sorting process it takes the smallest element in an
array and place at the lowest index position
Explanation:- Smallest element should be at first index position (for an ascending
array),2nd smallest element should be at second position and so on
int a[]={1,2,3,4,5}----5 elements
Note: index:- Of the first element will be 0 ,index of the second element will be 1 and so on
length of an array=len-1=6-1=05----gives the index of the last element in an array. */
/*Program 1:Sort an array using exchange selctionsort ,
pass the array A[] as an argument */
EXPLAINATION
public class ExplanationSelectionsort
{
public void Selection(int A[])
{
//array elements are {2,1,3,8,4,9,5,6,12,15}
int i=0,j,temp,small,pos;
for(i=0;i<10;i=i+1) //since there are 10 elements in a given array
{
small=A[i]; //small=A[0]=2
pos=i;//position of 2 is ,ie pos=0
for(j=i+1;j<10;j=j+1)//since the first element of an array 2
{ // to be compared with the next adjacent element 1
//{2,1,3,8,4,9,5,6,12,15,90}
if(A[j]<small) //A[j]=A[1]=1,small=2----1<2
{//condition is satisfied
small=A[j];//small=A[1]-----small=1
pos=j;//pos=1
}}
/*Swapping means exchanging of elements to
swap two variables, we need three variables
during swapping
A will get the value of B and vice versa and stores
in the third variable that is temp */
temp=A[i];//temp=A[0]-----temp=2 //temp=2
A[i]=A[pos];//A[i]=A[0]=2,A[pos]=A[1]=1 2=1
A[pos]=temp;//1=2 1=2
/*temp=2;
2=1;
1=2 ,wherever 1 is there replace by 2 and replace 2 by 1
in a given arraay {2,1,3,8,4,9,5,6,12,15,90}
so array will be now {1,2,3,4,5,6,8,9,12,15,90} */
}
[Link]("Array in ascending order ");
//to print array elements after swapping
for(i=0;i<10;i=i+1)
[Link](A[i]+"\t");
}}
PROGRAM 1:-
public class Selectionsort
{
public void Selection(int A[])
{
//array elements are {1,3,8,4,9,5,6,12,15,90}
int i=0,j,temp,small,pos;
for(i=0;i<3;i=i+1)//---It will read the element at its index position
{
small=A[i]; //small=A[0]--1
pos=i;//pos=0
for(j=i+1;j<3-i-1;j=j+1)//j=0+1=1<3
{
if(A[j]>small) //3<1
{
small=A[j];
pos=j;
}}
temp=A[i];//temp=A[0]=1
A[i]=A[pos];
A[pos]=temp;
}
[Link]("Array in ascending order ");
for(i=0;i<3;i=i+1)
[Link](A[i]+"\t");
}}
PROGRAM 2:-
public class Selectionsort1
{
public void Selection(String A[])
{
//array elements are {"A","B","E","D","C"}
int i=0,j,pos; String temp,small;
for(i=0;i<5;i=i+1)//---It will read the element at its index position
{
small=A[i]; //small=A[0]-A
pos=i;//pos=0
for(j=i+1;j<5;j=j+1)//j=0+1=1<3
{
if(A[j].compareTo(small)<0)//B<A------66<65
{
small=A[j];//small=A[1]="B"
pos=j;
}}
temp=A[i];//temp=A[i]="A"
A[i]=A[pos];
A[pos]=temp;
}
[Link]("Array in alphabetical order ");
for(i=0;i<5;i=i+1)
[Link](A[i]+"\t");
}}
PROGRAM 3:-
public class Try
{
public void Selection(String A[])
{
//array elements are {1,3,8,4,9,5,6,12,15,90}
int i=0,j,pos;String temp, small;
for(i=0;i<4;i=i+1)
{
small=A[i];
pos=i;
for(j=i+1;j<4;j=j+1)
{
if(A[j].compareTo(small) <0)
{
small=A[j];
pos=j;
}}
temp=A[i];
A[i]=A[pos];
A[pos]=temp;
}
[Link]("Array in ascending order ");
for(i=0;i<4;i=i+1)
[Link](A[i]+"\t");
}}
PROGRAM 4:-
public class Explanatio223
{
public void Selection22(int A[])
{
//array elements are {1,3,5,4,2}
int i=0,j,temp,small,pos;
for(i=0;i<5;i=i+1)//since there are 10 elements in a given array
{
small=A[i]; //small=A[0]=2
pos=i;//position of 2 is ,ie pos=0
for(j=i+1;j<5;j=j+1)// since the first element of an array 2
{ // to be compared with the next adjacent element 1
//{2,1,3,8,4,9,5,6,12,15,90}
if(A[j]>small) //A[j]=A[1]=1,small=2----1<2
{//condition is satisfied
small=A[j];//small=A[1]-----small=1
pos=j;//pos=1
}}
/*Swapping means exchanging of elements to
swap two variables, we need three variables
during swapping
A will get the value of B and vice versa and stores
in the third variable that is temp */
temp=A[i];//temp=A[0]-----temp=2 //temp=2
A[i]=A[pos];//A[i]=A[0]=2,A[pos]=A[1]=1 2=1
A[pos]=temp;//1=2 1=2
/*temp=2;
2=1;
1=2 ,wherever 1 is there replace by 2 and replace 2 by 1
in a given arraay {2,1,3,8,4,9,5,6,12,15,90}
so array will be now {1,2,3,4,5,6,8,9,12,15,90} */
}
[Link]("Array in descending order ");
Note:if(A[j]>small)-------descending array
if(A[j]<small)-------Ascending array
Only this is the change between tha descending array to ascending array
//to print array elements after swapping
for(i=0;i<5;i=i+1)
[Link](A[i]+"\t");
}}
DAY 2:-
1)Write a program to accept the weight of 5 people
and arrange them in ascending order using selection sort.
Sample Input:W[]={60,80,90,100,70}
Sample output:W[]={60,70,80,90,100}
2)Write a program to accept 5 integers and arrange them in
descendingorder using selection sorting technique
Sample Input:A[]={1,3,5,4,2}
Sample Output:A[]={5,4,3,2,1}
3)Write a program to accept 5 names of a person and arrange them
in an order
Sample input:-A[]={"B","D","A","C","E"}
Sample output:A[]={"A","B","C","D","E"}
Hint variable temp to be initialized to String
Instead of int A[],it should be String A[]
4) write a program in java to sort the array elements using
selection sort technique
Sample input{"Bangalore","Delhi","Chennai","Mumbai"}
Sample output{ "Bangalore","Chennai","Delhi","Mumbai"}
DAY 3:-
EXPLAINATION1:-
/* Defination of Bubble sort- During sorting process
it takes the highest element in an array and place at the highest
index position */
/* Explanation:-Highest element should be at highest index position
(for an ascending array),2nd highest element should be at the last but one
position and so on */
/* Program:Sort an array using Bubble sort , pass the array A[] as an argument */
public class BubblesortExplanation
{
public void Bubble(int A[])
{
//array elements are {2,1,3,8,4}
int i,j,temp,small,pos;
for(i=0;i<5;i=i+1)//
/*i loop is used to read the elements at
its index position */
for(j=0;j<5-i-1;j=j+1)
/* j loop is used to read the adjacent elements
(5-i-1),since the index of the last element is 4 */
{
if(A[j]>A[j+1])
{
//array elements are {2,1,3,8,4}
//A[j]=A[0]=2,A[j+1]=A[0+1]=A[1]=1,2>1
//Condition is satisfied
temp=A[j];//temp=A[j],temp=A[0],temp=2
A[j]=A[j+1];//A[j]=A[0]=2,A[j+1]=A[0+1]=1,2=1
A[j+1]=temp;//A[j+1]=A[0+1]=A[1]=1,1=2
// where ever 2 is there it has to replaced by 1 and 1 by 2
}}
[Link]("Array in ascending order ");
for(i=0;i<5;i=i+1)//{1,2,3,4,8}
// one more for loop is used to print the array elements after swapping
[Link](A[i]+"\t");///t gives the tab space between the elements
}}
/* Hw:{1,6,7,2,4,3}
{1,2,3,4,6,7}
}}*/
PROGRAM 5:-
public class Bubblesort
{
public void Bubble(int A[])
{
//array elements are {2,1,3,8,4}-----1,2,3,4,8
int i=0,j,k,temp,small,pos;
for(i=0;i<5;i=i+1) //-----2
for(j=0;j<4;j=j+1)
{
if(A[j]<A[j+1])
{
temp=A[j];
A[j]=A[j+1];
A[j+1]=temp;
}}
[Link]("Array in ascending order ");
for(k=0;k<5;k=k+1)
[Link](A[k]+"\t");
}}
PROGRAM 6:-
public class Hw
{
public void Bubble(String A[])
{
//array elements are {60,80,90,100,70}
int i=0,j,pos;String temp;
for(i=0;i<5;i=i+1)
for(j=0;j<(5-i-1);j=j+1)
{
if(A[j].compareTo(A[j+1])>0) //Ascending order
{
temp=A[j];
A[j]=A[j+1];
A[j+1]=temp;
}}
[Link]("Array in alphabetical order ");
for(i=0;i<5;i=i+1)
[Link](A[i]+"\t");
}}
DAY 4:-
1)Write a program to accaept the weight of 5 people and arrange them in Descending order
using Bubble sort.
Sample Input:W[]={60,80,90,100,70}
Sample output:W[]={100,90,80,70,60}
2)Write a program to accept 5 integers and arrange them in
descendingorder using Bubble sorting technique
Sample Input:A[]={1,3,5,4,2}
Sample Output:A[]={5,4,3,2,1}
3)Write a program to accept 5 names of a person and arrange them
in an order using bubble sort technique
Sample input:-A[]={"B","D","A","C","E"}
Sample output:A[]={"A","B","C","D","E"}
Hint variable temp to be initialized to String
Instead of int A[],it should be String A[]
1-Program ---Resultant array
Write a program in java to store
6 elements in p[]
4 elements in q[]
and produces an
r[] containing all elements of p and q
Sample Input:p[]={1,2,3,4,5,6}
q[]={7,8,9,10}
Sample Output:r[]={1,2,3,4,5,6,7,8,9,10}
2-Program----- Reversing an array
write a program in java to print the given
Array elements in the reverse order
sample input: A[]={1,2,3,4,5}
sample output A[]={5,4,3,2,1} */
DAY 5:-
EXPLAINATION
public class ExplantionResultantantarray
{
public void Program1(int p[],int q[])
{
int i,j,k,c=0;
//int p[]={1,2,3,4,5,6}; //r[]={1,2,3,4,5,6,7,8,9,10}
//int q[]={7,8,9,10};
int r[]= new int[10];/*r[] is the new array,for that you
have to declare the size of an array */
for(i=0;i<6;i=i+1)/*i loop is used to read the p
of array at its index position */
{
r[c]=p[i];/* each time counter will be incremented
r[c]=r[0]=1,r[1]=2,r[2]=3,r[3]=4,r[4]=5,r[5]=6 */
c=c+1;//1+1=2+1=3+1=4+1=5+1=6
}
for(j=0;j<4;j=j+1) /*j loop is used to read the q
of array at its index position */
{
r[c]=q[j];/* each time counter will be incremented
/r[6]=7,r[7]=8,r[8]=9,r[9]=10*/
c=c+1;//6+1=7+1=8
}
for(k=0;k<10;k=k+1)/* k of array the resultant array has to print both p[]
and Q[] elements in r[] */
[Link](r[k]+"\t");
}
public void Reverse(int A[])
{
//A[]={1,2,3,4,5};
int i;int len=5;
for(i=4;i>=0;i=i-1)
[Link](A[i]+"\t");
}}//5 4 3 2 1
// 1-Program
PROGRAM 7:-
public class Resultantantarray
{
public void Program1(int p[],int q[])
{
int i,j,k,c=0;
int r[]= new int[10];
for(i=0;i<6;i=i+1)
{
r[c]=p[i];
c=c+1;
}
for(j=0;j<4;j=j+1)
{
r[c]=q[j];
c=c+1;
}
for(k=0;k<10;k=k+1)
[Link](r[k]+"\t");
}
public void Reverse(int A[])
{
//A[]={1,2,3,4,5}
int i;
for(i=4;i>=0;i=i-1)
[Link](A[i]+"\t");
}}
EXPLAINATION:-
/*Write a program in java to findout the maximum,minimum and
sum of an array
Sample input:int A[]={1,2,3,4,5,6} int A[]={6,2,4,3,5,1}
maximum element=6
minimum element =1
sum=21
*/
public class MaxminExplanation
{
public void Sum(int A[])
{
//A[]={1,2,3,4,5,6};
int max=A[0];// //max=A[0]6
int min=A[0];// min=A[0]=6;
int sum=0;int i;
for(i=0;i<6;i=i+1)
{
if(A[i]>max)//A[i]=A[0]=1;if(A[1]>1)---if(1>1)//1>1 2>1 4>3 5>4 6>5
max=A[i];/*condition not saisfied max=2 max=3 max=4 max=5 max=6
in else part also condition not satisfied.*/
else if(A[i]<min)//1<1
min=A[i];
sum=sum+A[i];//sum=sum+A[i]=0+A[0]=0+1=1+2=3+3=6+4=10+5=15+6=21
/* A[]={1,2,3,4,5,6};
2nd time A[i]=A[1]=2
earlier max=1
if(2>1),condition is satisfied so max=A[i]=A[1]=2
sum=sum+A[i]=1(previous value)+A[1]=1+2(current value)=3;
next 3>2, condition satisfied so max=3
sum=sum+A[i]=3+A[2]=3+3=6;
next 4>3, condition satisfied so max=4
sum=sum+A[i]=6+A[3]=6+4=10;
next 5>4, condition satisfied so max=5
sum=sum+A[i]=10+A[3]=10+5=15;
next 6>5,condition satisfied so max=6
sum=sum+A[i]=15+A[3]=15+7=21;
since at the begining min=A[0]=1
so max=6 , min=1 and sum=21
*/
}
[Link]("maximum number is"+max);
[Link]("minimum number is"+min);
[Link]("sum of the number is"+sum);
}}
PROGRAM 8:-
public class MaxminProgram
{
public void Sum(int A[])
{
//A[]={1,2,3,4,5,6};
int max=A[0];
int min=A[0];
int sum=0;int i;
for(i=0;i<6;i=i+1)
{
if(A[i]>max)
max=A[i];
else if(A[i]<min)
min=A[i];
sum=sum+A[i];
}
[Link]("maximum number is"+max);
[Link]("minimum number is"+min);
[Link]("sum of the number is"+sum);
}}
EXPLAINATION:-
/*Write a program in java to accept the year of graduaion
from school as an integer value from the user using the
Binary search technique on the sorted array of integers given below
Output the message "Record exist"
if the value input is located in the array if not output
the message "Record doesnot exist"
{1982,1987,1993,1996,1999,2003,2006,2007,2009,2010} */
/* Program-To find name and corresponding phone no,
if it finds in an array it has to display "successful search"
otherwise "unsuccessful search"
String name[]={"Shalini",""Sujay","Poorvi"};
long phno[]={12345678,12344567,12345768};
*/
public class NamephnoExplanation
{
public void Phno(String n,long ph,String name[],long phno[])
{
//n=x,ph=1234,name[]={"x","y"z"} phno[]={1234,456,791}
//n and ph represents search element
//String name[]={"Shalini","Sujay","Poorvi"};
//long phno[]={12345,67899,777888};
//String n="Sujay";
//long ph=67899;
int a=0;int i;
for(i=0;i<3;i=i+1)
{
if([Link](name[i])&&ph==phno[i])
{
a=a+1;
//it can be written as a=a+1 in place of a=1;
//break;
}}
if(a==1)
[Link]("Successful search");
else
[Link]("Unsuccessful search");
}}
PROGRAM 9:-
public class NamephnoProgram
{
public void Phno(String n,long ph,String name[],long phno[])
{
int a=0;int i;
for(i=0;i<3;i=i+1)
{
if([Link](name[i])&&ph==phno[i])
{
a=1;
}}
if(a==1)
[Link]("Successful search");
else
[Link]("Unsuccessful search");
}}public class SujanProgram
{ public void Phno(String n,long ph,String name[],long phno[])
{ int a=0;int i;
for(i=0;i<3;i=i+1)
{ if([Link](name[i])&&ph==phno[i])
{ a=1;
break; }}
if(a==1)
[Link]("Successful search");
else
[Link]("Unsuccessful search");
}}
PROGRAM 10:-
/*Design a class to overload a function compare ( ) as follows:
(a) void compare (double, doublet) – to compare two double type values and print the
greater of the two floating values
(b) void compare (char, char) – to compare the numeric value of two character and print
the character with higher numeric value
(c) void compare (String, String) – to compare the equality of two strings whether equal or
not.
*/
public class Overload
{
public void Compare(double a,double b)
{
if(a>b)
[Link]("a is greater than b"+a);
else
[Link]("b is greater than a "+b);
} public void Compare(char a1,char b1)
{
if(a1>b1)
[Link]("a is greater than b"+a1);
else
[Link]("b is greater than a "+b1);
}
public void Compare(String a11,String b11)
{
if([Link](b11))
[Link]("Two strings are equal");
else
[Link]("Two strings are not equal"); }}
EXPLAINATION:-
/*Program -write a program in java to input and store rollno ,
*
* name,marks
in three subjects for n number of students in a
single dimensional array
and display the remarks based on average marks as given below -2005
averagemarks=total marks/3
Averagemarks Remarks
85-100 Excellent
75-84 Distinction
60-74 First class
40-59 Pass
lesser than 40 Fail
*/
public class Marksexplanation
{
public void remarks(String N[],int A[],int B[],int C[])
{
int i;
/* Since we are suppose to calculate Average and store the average
in the memory,we are suppose to allocate a memory for a variable Avg */
int avg[] = new int[3];
/* Since we are suppose to store the remarks
in the memory,we are suppose to allocate a memory for a variable R */
String R[] = new String[3];
for(i=0;i<3;i=i+1)
{
//name[]={"X","y","Z"};
// A[]={50,60,70};
// B[]={80,90,100};
//C[]={45,55,65};
//n=3 students
//when i=0--50+80+45=175/3=58.33=58-remark-pass
//when i=1--60+90+55=205/3=68.33=68-remark-first class
//when i=2----70+100+65=235/3=78.33=78-remark-Distinction
avg[i] = (A[i]+B[i]+C[i])/3;
if(avg[i]<40)
R[i]="Poor";
else if((avg[i]>=40)&&(avg[i]<=59))
R[i]="Pass";
else if((avg[i]>=60)&&(avg[i]<=74))
R[i]="First Class";
else if((avg[i]>=75)&&(avg[i]<=84))
R[i]="Distinction";
else if((avg[i]>=85)&&(avg[i]<=100))
R[i]="Excellent";
}
[Link]("Roll No\tName\tMark1\tMark2\tMark3\tAverage\tRemark");
for(i=0;i<3;i=i+1)
{
int rollno=i+1;
[Link](rollno+"\t"+N[i]+"\t"+A[i]+"\t"+B[i]+"\t"+
C[i]+"\t"+avg[i]+"\t"+R[i]);
}
}
}
PROGRAM 11:-
public class Marks
{
public void remarks(String N[],int A[],int B[],int C[])
{
int i;
int avg[]=new int[3];
String R[] = new String[3];
for(i=0;i<3;i=i+1)
{
avg[i] = (A[i]+B[i]+C[i])/3;
if(avg[i]<40)
R[i]="Fail";
else if((avg[i]>=40)&&(avg[i]<=59))
R[i]="Pass";
else if((avg[i]>=60)&&(avg[i]<=74))
R[i]="First Class";
else if((avg[i]>=75)&&(avg[i]<=84))
R[i]="Distinction";
else if((avg[i]>=85)&&(avg[i]<=100))
R[i]="Excellent";
}
[Link]("Roll No\tName\tMark1\tMark2\tMark3\tAverage\tRemark");
for(i=0;i<3;i=i+1)
{
int rollno=i+1;
[Link](rollno+"\t"+N[i]+"\t"+A[i]+"\t"+B[i]+"\t"+
C[i]+"\t"+avg[i]+"\t"+R[i]); } }}
PROGRAM 12:-
public class Sales
{
public void Program1_Sales1(int Sales[])
{
int i;double totalsales=0.0,averagesales=0.0;
for(i=0;i<6;i=i+1)//{1000,2000,3000,4000,5000,6000}-3500
{
totalsales=totalsales+Sales[i];//0+1000=1000+2000=3000+3000=6000+4000=10000+5000=15
000+6000
}
averagesales=totalsales/6;
[Link]("total sales in 6 days of the week "+totalsales);
[Link]("averagesales of entire week "+averagesales);
}}
/*[Link]-Write a program in java to accept sales of each
day of the week and print the total and average sales of one
week (Working days-6)
[Link]-Progarm to read marks of 5 subjects of n number of student
and store them under an array ,calculate the total and average
marks of the student. */
PROGRAM 13:-
public class SalesAverage
{
public void Program1_Sales1(int Sales[])
{
//Sales[]={1000,2000,3000,4000,5000,6000}
int i;double totalsales=0.0,averagesales=0.0;
for(i=0;i<6;i=i+1)//since we are suppose to find the sales for six days
{
totalsales=totalsales+Sales[i];//21000//o+1000=1000+2000=3000+3000=6000+4000=10000
averagesales=totalsales/6;}//10000+5000=15000+6000=21000
[Link]("total sales in 6 days of the week "+totalsales);
[Link]("averagesales of entire week "+averagesales);
}
public void Program2_sumaverage(int marks[])
{
//marks[]={10,20,30,40,50}
int i;double total=0.0,average=0.0;
for(i=0;i<5;i=i+1)/*since we are suppose to find the average marks of
5 subject of a person */
{//0+10=10+20=30+30=60+40=100+50=150
total=total+marks[i];// 5 subject marks are stored in a variable total
//total={10,20,30,40,50}=150
average=total/5;}
//average=150/5=30
[Link]("total marks of 5 subjects "+total);
[Link]("average marks of 5 subjects "+average);}}
PROGRAM 14:-
public class SalesAverage1
{
public void Program1_Sales1(int Sales[])
{
int i;double totalsales=0.0,averagesales=0.0;
for(i=0;i<6;i=i+1)//{1000,2000,3000,4000,5000,6000}-3500
{
totalsales=totalsales+Sales[i];//0+1000=1000+2000=3000+3000=6000+4000=10000+5000=15
000+6000
}
averagesales=totalsales/6;
[Link]("total sales in 6 days of the week "+totalsales);
[Link]("averagesales of entire week "+averagesales);
}
public void Program2_sumaverage(int marks[])
{
int i;double total=0.0,average=0.0;
for(i=0;i<5;i=i+1)//{100,90,80,70,60}
{total=total+marks[i];}
average=total/5;
[Link]("total marks of 5 subjects "+total);
[Link]("average marks of 5 subjects "+average);}}
PROGRAM 15:-
/*Program -
Shasha travels Private Limited announces the following
discount to its customers
Ticket amount Discount
>70000 18%
55001 to 70000 16%
35001 to 55000 12%
25001 to 35000 10%
<25001 2%
Write a program to input names and ticket amount for the customer
and calculate discount and net amount to be paid
Display the output in the following for each customer
slno Name Ticket charges Discount Net amount
--- ---- ------------ ------- -----------
Assume that there are 3 customers ,fisrst customer serial no 1,
second customer serial number 2 and so */
public class Shasha
{
public void Shasha1(String N[],int Ticket[])
{
int i;
double Dis[]=new double[3];
double Net[]=new double[3];
for(i=0;i<3;i=i+1)
{
if(Ticket[i]>70000)
Dis[i]=0.18;
else if(Ticket[i]>55000 && Ticket[i]<=70000)
Dis[i]=0.16;
else if(Ticket[i]>35000 && Ticket[i]<=55000)
Dis[i]=0.12;
else if(Ticket[i]>25000 && Ticket[i]<=35000)
Dis[i]=0.10;
else if(Ticket[i]<=25000 )
Dis[i]=0.02;
Net[i]=Ticket[i]-(Ticket[i]*Dis[i]);
Dis[i]=Ticket[i]*Dis[i];
[Link]("slno"+"\t"+"Name"+"\t"+"Ticketcharges"+
"\t"+"Discount"+
"\t"+"Netamount");
for(i=0;i<3;i=i+1)
{
int sno=i+1;
[Link](sno +"\t"+ N[i] +"\t"+"\t"+
Ticket[i]+"\t"+Dis[i]+"\t"+Net[i]);
}}}
PROGRAM 16:-
/*Program -
Shasha travels Private Limited announces the following
discount to its customers
Ticket amount Discount
>70000 18%
55001 to 70000 16%
35001 to 55000 12%
25001 to 35000 10%
<25001 2%
Write a program to input names and ticket amount for the customer
and calculate discount and net amount to be paid
Display the output in the following for each customer
slno Name Ticket charges Discount Net amount
--- ---- ------------ ------- -----------
Assume that there are 3 customers ,fisrst customer serial no 1,
second customer serial number 2 and so on
*/
public class Shashatravels
{
public void Discount(double A[],String N[])
{
/* Ticket amount paid by the customer
A[]={45000,55000,65000} */
/* Names of the customers
N[]={"A","B","C"}; */
/*suppose to calculate the discount availed as well as
net amount after discount */
int i;
/* Since we are suppose to calculate Discount and store the Discount
in the memory,we are suppose to allocate a memory for a variable D */
double D[]= new double[3];
/* Finally we are suppose to calculate the net amount after discount avail
we are suppose to allocate a memory for a variable net */
double Net[]=new double[3];
for(i=0;i<3;i=i+1)
{//{"x","y","z"}
//A[]={45000,55000,65000}
if(A[i]<25001)
D[i]=0.02*A[i];
else if(A[i]>25001 && A[i]<=35000)
D[i]=0.1*A[i];
else if(A[i]>35001 && A[i]<=55000)
D[i]=0.12*A[i];//i=0=45000;D[i]=012*45000=5400,i=1=55000=0.12*55000=6600
else if(A[i]>=55001 &&A[i]<=70000)
D[i]=0.16*A[i];//i=2=0.16*65000=10,400
else if(A[i]>70000)
D[i]=0.18*A[i];
Net[i]=A[i]-D[i] ;/* for i=0=Net[i]45000-5400=39600,for i=1=55000-6600=48400*/
}//i=2=65000-10400=54600
[Link]("Serialno\tName\tTicketCharges\tDiscount\t Netamount ");
for(i=0;i<3;i=i+1)
{ int slno=i+1;
[Link](slno+"\t"+"\t"+ N[i]+"\t"+A[i]+"\t"+"\t"+D[i]+"\t"+"\t"+Net[i]);
}}}
PROGRAM 17:-
public class Shashatravels
{
public void Discount(double Amount[],String n[])
{
int i;
int netamount[]=new int[3];
double discount[]=new double[3];
for(i=0;i<3;i=i+1)
{
if(amount[i]<25001)
discount[i]=0.02*Amount[i];
else if ((amount[i]>=25001)&&(amount[i]<=35000))
discount[i]=0.1*Amount[i];
else if ((amount[i]>=35001)&&(amount[i]<=55000))
discount[i]=0.12*Amount[i];
else if ((amount[i]>=55001)&&(amount[i]<=70000))
discount[i]=0.16*A[i];
else if ((amount[i]>=70001))
discount[i]=0.18*Amount[i];
else
netamount=A[i]-discount[i];
}
[Link]("slno \t name\t ticketcharges\t Discount\t netamount");
for(i=0;i<3;i=i+1)
{
int slno=i+1;
[Link](slno+"\t"+
n[i]+"\t"+A[i]+"\t"+discount[i]+"\t"+netamount[i]); }}}
PROGRAM 18:-
public class Expicit
{
public void Explicit()
{
double a=22;double b=7;
double result=0.0;
result=(a/b);
[Link]("addition of two numbers is"+result);
}}
/*Multi dimensional array:-It consist of a row and a column,
it is reprented as int A[][]----where first bracket represents a row and
second bracket represent a column.
Matrix programs represents multi dimensional array
Example:-int A[][]={{1,2},{3,4}}
Array elements are represented within curly braces
{1,2}----are the elements of the first row,which is at the index 0
{3,4}----are the elements of the second row,which is at the index 1
*/
/* Question 1:-Write a program in java to print 2*2 matrix the array
elements are A[][]={{1,2},{3,4}}*/
EXPLAINATION:-
public class Twointotwomatrixexplanation// 1 2
{ // 3 4
public void Matrix()
{
int i,j;
int A[][]={{1,2},{3,4}};
for(i=0;i<2;i=i+1)//i=0,j=0 i=0,j=1
{/* 1 and 2 are the elements of First row-------they are present
at the index o---that is first row ,index is 0 */
/* 3 and 4 are the elements of second row-------they are present
at the index 1---that is second row ,index is 1 */
for(j=0;j<2;j=j+1)//1 2
// 34
{
/* when i=0,j=0,0<2,condition is satisfied,so it takes the element 1 and prints the element 1
at index 0 of first row nexti=0,j=1,1<2,condition is satisfied,so it takes the element 2 and
prints the element 2 at the index 1 of first row like this 1 2 since println is there it leaves a
gap of one line next i=0,j=2,2<2,condition not satisfied,when condition not satisfied i value
will be incremented new value of i is 1, i=1,j=0,0<2(j always starts from scratch for the new
value of i),it takes the element 3,and prints the element at the index 0 of second row next
i=1,j=1,1<2,it takes the element 4,and prints the element at the index 1 of second row next
i=1,j=2,2<2,condition not satisfied ,so it comes out of the current loop */
[Link](A[i][j]+" ");}
[Link]();
}}}
PROGRAM 19:-
public class Twointotwo
{
public void Matrix()
{
int i,j;
int A[][]={{1,1},{2,2}};
int B[][]={{1,1},{2,2}};
for(i=0;i<2;i=i+1)
{
for(j=0;j<2;j=j+1)
{
[Link](A[i][j]+B[i][j]+" ");}
[Link]();
}
}
public void Matrix2()
{
int i,j;
int A[][]={{5,5},{5,5}};
int B[][]={{1,1},{1,1}};
for(i=0;i<2;i=i+1)
{
for(j=0;j<2;j=j+1)
{
[Link](A[i][j]+B[i][j]+" ");}
[Link]();
}}}
PROGRAM 20:-
public class Threeintothree
{
public void Matrix()
{
int i,j;
int A[][]={{1,2,3},{4,5,6},{7,8,9}};
for(i=0;i<3;i=i+1)
{
for(j=0;j<3;j=j+1)
{
[Link](A[i][j]+" ");}
[Link]();
}}}
PROGRAM 21:-
public class TwoXTwo
{
public void Matrix()
{
int i,j;
int A[][]={{1,2},{3,4}};
for(i=0;i<2;i=i+1){
for(j=0;j<2;j=j+1)
{
[Link](A[i][j]+" ");}
[Link]();
}
}
}
PROGRAM 22:-
public class Shivani
{
public void Shivani2()
{
int A[][]={{1,2},{3,4}};
int i,j;int r=0;
for(i=0;i<2;i=i+1)
{
for(j=0;j<2;j=j+1)
{
r=(int)([Link](A[i][j],2));
[Link](r+" ");
}
[Link]();
}}}
PROGRAM 23:- /* Write a program in java to add sum of the diagonal elements
Ex:int A[][]={{1,2,9},{4,5,6},{7,8,9}}
sum=9+5+7=21*/
public class Diagonal1{
public void Right()
{
int A[][]={{1,2,9},{4,5,6},{7,8,9}};
int i,j,sum=0;
for(i=3;i>0;i=i-1)
{
for(j=0;j<=2;j=j+1)
{
if(i==j)
{
sum+=(A[i][j]);
break;
}}}
[Link]("sum of the elements diagonally is"+sum);
}}
PROGRAM 24:-
public class Addition{
public void Matrix()
{
int i,j,result=0;
int A[][]={{5,5},{5,5}};
int B[][]={{1,1},{1,1}};
for(i=0;i<2;i=i+1)//i=0,j=0 i=0,j=1
{
for(j=0;j<2;j=j+1)//1 2
// 34
{
result=A[i][j]+B[i][j];
[Link](result+" ");}
[Link]();
}}
public void Matrix1()
{
int i,j;
int A[][]={{1,2,3},{4,5,6}};
int B[][]={{2,2,2},{2,2,2}};
for(i=0;i<2;i=i+1)//i=0,j=0 i=0,j=1
{
for(j=0;j<3;j=j+1)//1 2
// 34
{
[Link](A[i][j]*B[i][j]+" ");}
[Link]();
}}
public void M3()
{
int i,j;
int A[][]={{1,2},{3,4},{5,6},{7,8},{9,10}};
for(i=0;i<5;i=i+1)//i=0,j=0 i=0,j=1
{
for(j=0;j<2;j=j+1)//1 2
// 34
{
[Link](+(int)(A[i][j]*0.5)+" ");}
[Link]();
}} public void M4()
{ int i,j;int se=0;int so=0;
int A[][]={{2,4},{3,1}};
for(i=0;i<2;i=i+1)//i=0,j=0 i=0,j=1
{for(j=0;j<2;j=j+1)//1 2
// 34
{ if(A[i][j]%2==0)
{ se=se+A[i][j];}
else if(A[i][j]%2!=0)
{ so=so+A[i][j];}}}
[Link]("sum of even"+se);
[Link]("sum of odd"+so);
}}
PROGRAM 25:-
public class Rectangle
{
public void Matrix()
{
int i,j;
int A[][]={{1,2,3},{4,5,6}};
for(i=0;i<2;i=i+1)
{
for(j=0;j<3;j=j+1)
{
[Link](A[i][j]+" ");}
[Link]("\n");
}}}
PROGRAM 26:-
public class Swati
{ // 3 4
public void Matrix()
{
int i,j;
int A[][]={{1,2},{3,4}};
for(i=0;i<2;i=i+1)//i=0,j=0 i=0,j=1
{
for(j=0;j<2;j=j+1)//1 2
// 34
{
[Link](A[i][j]*A[i][j]+" ");}
[Link]();
}}
public void Matrix2()
{
int i,j;
int A[][]={{1,2},{3,4}};
for(i=0;i<2;i=i+1)//i=0,j=0 i=0,j=1
{
for(j=0;j<2;j=j+1)//1 2
// 34
{
double result=([Link](A[i][j],2));
//[Link](A[i][j]*A[i][j]+" ");}
[Link](+(int)result+" ");}
[Link](); }}}
PROGRAM 27:-
/*Write a program in java to quadrapule the array elements
Sample input:int A[][]={{1,1,1,1},{1,1,1,1},{1,1,1,1},{1,1,1,1}}
Sample output:int A[][]={{4,4,4,4},{4,4,4,4},{4,4,4,4},{4,4,4,4}}
Quarapule means it should contain four rows and four columns and
all the elemts of a row and a column to be multiplied by 4 */
public class Quadra1
{
public void Matrix(int A[][])
{
int i,j;
///int A[][]={{1,1,1,1},{1,1,1,1},{1,1,1,1},{1,1,1,1}};
for(i=0;i<4;i=i+1)
{
for(j=0;j<4;j=j+1)
{
[Link](A[i][j]*4+" ");}
[Link]();
}}}
PROGRAM 28:-
//Example on implicit and explicit
public class A
{
public void Explicit1()
{
double a=22;double b=7;
int result=0;
result=(int)(a/b);
[Link]("addition of two numbers is"+result);
}
//Explicit type conversion -output 3
public void Impicit()
{
double a=22;double b=7;
double result=0;
result=(a/b);
[Link]("addition of two numbers is"+result);
}}
//Implicit type conversion -output 3.142
PROGRAM 29:-
public class LogicalOperator {
public void Lo()
{
int a = 1, b = 2, c = 9;
boolean result;
// At least one expression needs to be true for result to be true
result = (a > b) || (c > a);
//as per truth table one is f and the other is t ,it will be t */
[Link](result);
// All expression must be true from result to be true
result = (a > b) && (c > a);/* f &&t=f */
[Link](result);
}
}