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

Computer Assignment

Here is the program to input the basic salary of a person and calculate 15% of basic salary as HRA: import java.util.Scanner; class Q5 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Enter basic salary: "); double basicSalary = sc.nextDouble(); double hra = basicSalary * 0.15; System.out.println("HRA = " + hra); } } Output: Enter basic salary: 10000 HRA = 1500.0 In this program, we take the basic salary as input from the user using Scanner class

Uploaded by

Priyam Saha
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views

Computer Assignment

Here is the program to input the basic salary of a person and calculate 15% of basic salary as HRA: import java.util.Scanner; class Q5 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Enter basic salary: "); double basicSalary = sc.nextDouble(); double hra = basicSalary * 0.15; System.out.println("HRA = " + hra); } } Output: Enter basic salary: 10000 HRA = 1500.0 In this program, we take the basic salary as input from the user using Scanner class

Uploaded by

Priyam Saha
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 61

Co

mpu
ter
Assi
gnm Name: Priyam Saha
ent CLASS: X
SEC:B
ROLL NO.:14
SESSION:2022-23
SUBJECT:Computer Project File

ACKNOWLEDGEMENT
I would like to express my special thanks of gratitude
to my teacher Mrs. Preeti Sarkar, who gave me
the golden opportunity to do this wonderful project of
Computer Assignment File.

Who also helped me in completing my project.


I came to know about so many new thing I am really
thankful to them.

Secondly I would also like to thank my parents and friends


who helped me a lot in finalizing this project within the
limited time frame.

Priyam Saha
X-B
Teacher’s Signature

Contents
Sl.No. Assignment Topic Pg. No.

1 Introduction 1

2 Temperature Conversion 2-4

3 Area and circumference of circle 5-6

4 Input of three real numbers 7-9

5 A number divisible by 5 10-11

6 Input the basic salary of a person 12-13

7 Input three sides of a triangle 14-15

8 To calculate fine 16-17

9 To calculate grades 18-20

10 To display automorphic number 21-23

11 To accept and check whether the no. is 24-26


diserium number or not
12 To print the sum of even number series 27-28
13 To print the pattern 29-31

14 To display the pattern 32-33

15 To find sum of first 20 terms of a series 34-35

16 Reverse Array 36-38

17 To declare an integer array and print the 39-41


values in third array
18 To find: 42-44
Largest and smallest, product of odd number,
Sum of even number
19 To Input a sentence and find 45-47
no. of Odd no., no. of letters present
20 To accept a word/ String and display the new 48-50
string
21 To enter a string or sentence and display the 51-53
longest word and the length of the longest
word
22 Conclusion 54

23 Bibliography 55

24 Declaration 56

25 Photo gallery 57
INTRODUCTION
Every School needs to maintain data bases of the student.
The data base on the students is required for general
purpose like collection fees using this software, under the
Office module, the database on the students can be created,
modified. The same can be used to verify whether any
student is due for payment of term fees etc.

It is designed to introduce a conducive and structured


information exchange institutions to supervise student-
related activities.

They are designed with diverse application potentials ranging


from simple management of students’ records at school to
management of all student-related functions as well as
administrative functions of a university or a chain of
educational establishments. This software is useful to
maintain updated and error free status of all the students.

The Motive of this software is to dilute the work of office


staffs, and to reduce the use of paper.

Pg-01
Assignm
ent No.: TOPIC: - Conversion of temperature from
Celsius to Fahrenheit
01 And vice versa.
Pg-02
Q1: Write a program in java accept temperature in celcius
and covert it to Fahrenheit and vise-versa
Solution:-
import java.util.*;
class c2f_f2c_menu_driven {
public static void main (String [] args)
{
float t;
int ch;
Scanner ki=new Scanner (System.in);
do {
System.out.print("\n 1. Centigrade to Fahrenheit");
System.out.print("\n 2. Fahrenheit to Centigrade");
System.out.print("\n 0. Exit");
System.out.print("\nEnter temperature ");
t=ki. next Float ();
System.out.print("\nEnter your choice ");
ch=ki.nextInt();
switch(ch){
case 1:
System.out.print("\nIn Farenhiet "+c2f(t));
break;

case 2:
System.out.print("\nIn Centigrade "+f2c(t));
break;

case 0:
System.exit(0);
break;

default:
System.out.print("Wrong choice ????"+ch+" Invalid option ");
break;
}//end switch
}while(ch!=0);
return;
}//end main

public static float c2f(float c)


{
return(9*c/5+32);
}//end c2f

public static float f2c(float f)


{
return(5*(f-32)/9);
}//end f2c
}//end class; Pg-03
OUTPUT:-
1. Centigrade to Fahrenheit
2. Fahrenheit to Centigrade
0. Exit
Enter temperature 40

Enter your choice 1

In Fahrenheit 104.0
1. Centigrade to Fahrenheit
2. Fahrenheit to Centigrade
0. Exit
Enter temperature 56

Enter your choice 2

In Centigrade 13.333333
1. Centigrade to Fahrenheit
2. Fahrenheit to Centigrade
0. Exit

VARIABLE DESCRIPTION: -

NAME OF THE VARIBLE DATATYPE PURPOSE

t float Stores the temperature


ch int Stores the user’s choice
c float Represents the Celsius
temperature
f Float Represents the Fahrenheit
temperature

Pg-04
Assignment No.: 02
TOPIC: - Area and circumstances of circle.

Pg-05
Q2: Write a program to calculate the area and circumference of the
circle.

Solution:-

import java.io.*;
import java.util.*;
class Q2
{

public static void main(String[]args)


{

float r, pi=3.142f, area, circum;


Scanner ki=new Scanner(System.in);
System.out.print("Enter the radius of the circle");
r=ki.nextFloat();

area=pi*r*r;
circum=2*pi*r;

System.out.print("The area of the circle is"+area+"/n The circumference of the circle


is"+circum);
return;

}//end main
}//end class

OUTPUT:-

Enter the radius of the circle: 4


The area of the circle is50.272
The circumference of the circle is25.136

VARIABLE DESCPRITION:-
NAME OF THE VARIABLE DATATYPE PURPOSE

r float Stores the radius


pi float Stores the value of pi
area float Stores the area of the
circle
Circum float Stores the circumstance
of the circle
Pg-06
As
signmen TOPIC: -X = Product of integer portion
sum of decimal portion
t No.: 03

Pg-07
Q3 Write any program to enter any three real numbers and
calculate X where :

X = Product of integer portion


sum of decimal portion

Solution:

import java.io.*;
import java.util.*;
class real_no
{
public static void main(String [] args)
{
float n,x,pro_i=1,sum=0.0f;
int i;
Scanner ob=new Scanner(System.in);
for(i=1;i<=3;i++)
{
System.out.print("\nEnter "+1+" th no ");
n=ob.nextFloat();
pro_i*=(int)n;
sum+=n-(int)n;
}

x=pro_i/sum;//mant((float)n-(int)n));
System.out.print("\nResultant "+x);
return;
}
};

Pg-08
OUTPUT:-

Enter 1 th no 1
Enter 1 th no 85
Enter 1 th no 58

Resultant Infinity

VARIABLE DESCRIPTION:-

NAME OF THE DATATYPE PURPOSE


VARIABLE

n Float Stores the number


x Float Stores the product and the sum
pro_i Float Stores the value of n
sum Float Stores the sum
i int Help to run the loop

Pg-09
Assignm
ent No.: TOPIC: -Divisible by 5 or not

04

Pg-10
Q4 :- Write a program to check whether the
number is divisible by 5 or not.
SOLUTION:-

import java.util.*;
class Q4_
{
public static void main(String[]args)
{
int i;
Scanner ki=new Scanner(System.in);
System.out.print(" Enter the no.");
i=ki.nextInt();
if (i%5==0)
System.out.print(i+" the number is divisible by 5");
else
System.out.print(i+" the number is not divisible by 5");
return;
}
}

OUTPUT:-
Enter the no.25
25 the number is divisible by 5

VARIABLE DESCRIPTION:-

NAME OF THE VARIABLE DATATYPE PURPOSE

i int Stores the no. which is


entered by the user.

Pg-11
Assignm
ent No.: TOPIC: -Divisible by 5 or not

05

Pg-12
Q5 Write a program to input the basic salary of a person. He or she
get 15%of the basic as HRA, 15% of the basic as Convenience
allowances and 10% of the basic as medical allowances. The total
salary is calculated by adding basic +HRA +Convenience
allowances + medical allowances. Calculate and print the total
salary of the person.

Solution:-

import java.util.*;
class Q5
{
public static void main(String[]args)
{
float i, HRA, CA, MA, TS;
Scanner ki= new Scanner(System.in);
System.out.print("Enter the basic salary");
i=ki.nextFloat();
HRA=15/100*i;
CA=15/100*i;
MA=10/100*i;
TS=i+HRA+CA+MA;
System.out.print("total salary= "+TS);
}
}

OUTPUT:-
Enter the basic salary8000
Total salary= 8000.0

VARIABLE DESCRIPTION:-

NAME OF THE VARIABLE DATATYPE PURPOSE

i float stores the basic salary


HRA float stores the HRA
CA float stores the convince
allowances
MA float stores the medical
allowances
TS float stores the total salary
Pg-13
Assignm
ent No.: TOPIC: -Triangle

06

Pg-14
Q6)Write a programme to enter the three sides of triangle. Decide
whether it is a scalene, isosceles or equilateral triangle.
Solution:-
import java.util.*;
class Q6{
public static void main (String [] args){
int a, b, c;
Scanner ki= new Scanner (System.in);
System.out.print ("\n Enter the three number");
a=ki.nextInt();
b=ki.nextInt();
c=ki.nextInt();
if(((a+b)>c)&&((a+c)>b)&&((b+c)>a)){
System.out.print ("it forms an Triangle");
if((a==b)&&(b==c))
System.out.print ("Equilateral Triangle");
if((a==b)&&(b==c))
System.out.print ("\nIsosceles Triangle");
else
System.out.print ("\nScalene Triangle");
}
else
System.out.print ("\nCannot form a Triangle");
return;
}
};

OUTPUT:-
Enter the three number
7
4
5

It forms an Triangle
Scalene Triangle

VARIABLE DESCRIPTION:-

NAME OF THE VARIABLE DATATYPE PURPOSE

a int stores the first side


b int stores the second side
c int stores the third side
Pg-15
Assignm
ent No.: TOPIC: -A library charges fine for book
returned late.

07

Pg-16
Q7)A library charges fine for book returned late.Following are the
fines. First five days 2 rupees per day six to ten days 5
rupees,above 10 days 10 rupees per day.Design a programme to
calculate the fine assuming that a book is returned N days late.

Solution:-

import java.util.*;
class Q7{
public static void main (String[]args){
int n;
Scanner ki=new Scanner (System.in);
System.out.print ("Enter the no. of days ");
n=ki.nextInt();
if (n<=5)
System.out.print("You have to pay"+ (n*2)+"rupees”");
else if ((n>6)&&(n<=10))
System.out.print("You have to pay"+ (n*5)+"rupees");
else if (n>10)
System.out.print("You have to pay"+(n*10)+"rupees");
return;
}
};

OUTPUT:-
Enter the no. of days 5
You have to pay 10 rupees.

VARIABLE DESCRIPTION:-

NAME OF THE VARIABLE DATATYPE PURPOSE

n int stores the no. of days

Pg-17
Assignment No.:08
IC: -
Calculating the grade
Pg-18
Q8)Using if-else statements write a programming to calculate the
grade as per the given criteria.

Marks. Grade
>=80 and <100 Excelent
>=70 and <80 1st Div
>=60 and <70 2nd Div
>=50 and <60 3rd Div
Less then 50 Passed under considered.

Solution:-

import java.io.*;
import java.util.*;
class Q8{
public static void main(String[]args)
{
int i;

Scanner ki=new Scanner(System.in);


System.out.print("\n Enter the marks of the student ");
i=ki.nextInt();

if((i>=80)&&(i<=100))
System.out.print("\n Excellent ");

else if((i>=70)&&(i<80))
System.out.print("\n First div. ");

else if((i>=60)&&(i<70))
System.out.print("\n Second div. ");

else if((i>=50)&&(i<=60))
System.out.print("\n Third Div. ");

else if(i<50)
System.out.print("\n Passed under consideration ");

};

Pg-19
OUTPUT:-
Enter the marks of the student 0

Passed under consideration

Enter the marks of the student 70

First div.

VARIABLE DESCRIPTION:-

NAME OF THE VARIABLE DATATYPE PURPOSE

i int stores the marks of the


student

Pg-20
Assignm
ent TOPIC: -Automorphic Number

No.:09

Pg-21
Q9)Write a programme to display Automorphic Number.
Solution:-
import java.io.*;
import java.lang.*;
class automorphic_series
{
public static void main(String [] args) throws IOException
{
int a,i,s,st,p;
for(s=1;;s++)
{
st=s;
for(i=0;st!=0;st/=10,i++);
p=i-1;
a=s*s;
for(;i>=0;a/=10,i--)
st+=(a%10)*Math.pow(10,p--);

if(st==s)
System.out.println(st);
}

}
public static int getint() throws IOException
{
BufferedReader ki=new BufferedReader(new InputStreamReader(System.in));
return(Integer.parseInt(ki.readLine()));
}

Pg-22
OUTPUT:-
1
5
6
963
9867
90629087
233930550

VARIABLE DESCRIPTION:-

NAME OF THE VARIABLE DATATYPE PURPOSE

i int stores the marks of the


student
st int stores the value of s
s int stores the no.
a int helps the no. to get
multiplied
p stores the product

Pg-23
A
ssignme Topic: - Disarium number

nt
No.:10

Pg-24
10) Write a programme to accept a number and check whether it is
a Disarium Number or not.

Solution:-
import java.util.*;

class disarium_no{
public static void main(String [] args)
{
int n,d,st,sum;

Scanner ki=new Scanner(System.in);


System.out.print("\nEnter a no ");
n=ki.nextInt();
st=n;
for(d=0;st!=0;st/=10,d++);//find the no of digits
st=n;
for(sum=0;st!=0;st/=10)
{
sum+=Math.pow((st%10),d--);
}
//System.out.print(sum);
if(sum==n)
System.out.print(n+" is a diserium no.");
else
System.out.print(n+" is not a diserium no.");
return;
}
};

Pg-25

Output:-

Enter a no 1
1 is a diserium no.
Enter a no 548
548 is not a diserium no.
VARIABLE DESCRIPTION:-

NAME OF THE VARIABLE DATATYPE PURPOSE

n int stores the number


d int stores the no. of digit
st int stores the value of n
sum int stores the sum

Pg-26
Assignm
ent No.: Topic:- Even number series

11

Pg-27

11) Write a programme to print sum of even number series.


Solution:-

import java.util.*;

class Q11{
public static void main(String [] args)
{
int i,n,s=0;
Scanner ki=new Scanner(System.in);
System.out.print("\nEnter the value of s \n");
n=ki.nextInt();
for (i=2;i<=n;i++){
if (i%2==0)
s+=i;
}
System.out.print (s);

return;
}
};

Output:-
Enter the value of s
41
420

Variable description:-

NAME OF THE VARIABLE DATATYPE PURPOSE

i int it stores all the even no. up


till the value of n
n int stores the no. input by the
user
s int stores the sum of i

Pg-28
Assignm
ent No.:
Topic- *
12 ***
******
*********
******
***
*

Pg-29

12) Write a Program to print the following pattern


*
***
******
*********
******
***
*
Solution:-
class Q12ClassX{
public static void main(String [] args) {
int i,b=20;
for(i=1;i<=9;i+=2) {
prn(' ',b--);
prn('*',i);
System.out.println(); }//'for' loop for the upper group
b+=2;
for( i-=4;i>=1;i-=2) {
prn(' ',b++);
prn('*',i);
System.out.println(); }//'for' loop for the lower group
}//end main
public static void prn(char c,int b) {
int k;
for(k=1;k<=b;k++){
System.out.print(c); }
return; }
};

Pg-30
Output:-
the output is *
***
*****
*******
*********
*******
*****
***
*

Variable description :-

NAME OF THE VARIABLE DATATYPE PURPOSE

i int Print the stars


k int it helps in increment and
decrement of the blank space
b int Stores the blank space

Pg-31
Assignm
ent No.: Topic:- 11111

13 3333
555
77
9

Pg-32
13) Write a programme to display the given number pattern.
11111
3333
555
77
9
Solution:-
class Q13{
public static void main(String [] args)
{
int i,j,k;
for(i=5,k=1;i>=1;i--,k+=2){
for(j=1;j<=i;j++){
System.out.print(k);
}
System.out.println();
}
}
};

output:-
11111
3333
555
77
9

Variable Description:-

Name of the variable Datatype Purpose

i int it print the times of the no.


j int it print the no. from 1 to 5
k int it decrease i by 1
Pg-33
Assignment No.: 14
Topic:-Series add

Pg-34
14)Write a programme to find the sum of Frist 20 terms of the
series.
S= (2/3) + (4/5) + (8/7) + (16/9) +.............
Solution: -
import java.util.*;
class Q14 {
public static void main (String [] args) {
float i,j,s=0.0f,m;
Scanner ki= new Scanner (System.in);
System.out.print (“enter the value of m”);
m=ki.nextFloat();
for (i=2,j=3.0f;i<=m;i*=2,j+=2)
{
s+=i/j;
}
System.out.print (“\n the result is “+s);
return;
}
}

Output:-

enter the value of m5

the result is 1.4666667

Variable Description:-

Name of the variable Datatype Purpose

i float Stores the numerator


j float Stores the denominator
s float Stores the sum
m float Stores the last no.

Pg-35
Assignment No.: 15
Topic:-Reverse array

Pg-36
Q15)Write a program to accept 10 integers in an array and print
the reverse array

Solution:-

importjava.util.*;

class Q15reverse_array{
public static void main(String [] args)
{int i;
int []ar=new int[10];
Scanner ki=new Scanner(System.in);
System.out.print("\nEnter int s");
for(i=0;i<10;i++){
ar[i]=ki.nextInt();
}//collecting values
System.out.println("\nPrinting array in reverse order");
for(i=9;i>=0;i--){
System.out.print(ar[i]+"\t");
}//collecting value

return;
}
};

Pg-37
OUTPUT:-

Enter int s
14
12
5
3
6
5
463
45
42
45

Printing array in reverse order


45 42 45 463 5 6 3 5 12 14
Variable Description:-

Name of the variable Datatype Purpose

i int Stores the number which is


inputted by the user

Pg-38
Assignment No.: 16
Topic:-Merging array

Pg-39
16)Write a program to declare an integer array to accept 6
elements, another array to store 4 elements. Merge both the arrays
and print the values in a third array.

SOLUTION:-
import java.util.*;
class Q16{
public static void main(String [] args){
int i,j,k;
Scanner ki=new Scanner(System.in);
int [] a=new int[6];
int [] b=new int[4];
int []c=new int[10];
System.out.println("Enter 6 values for the first array ");
for(i=0;i<6;i++) {
System.out.print("\nEnter "+(i+1)+"-th value ");
a[i]=ki.nextInt();
}//end for
System.out.println("Enter 4 values for the second array ");
for(j=0;j<4;j++){
System.out.print("\nEnter "+(j+1)+"-th value ");
b[j]=ki.nextInt();
}//end for
for(i=0,k=0;i<6;i++,k++) {
c[k]=a[i]; }
for(j=0;j<4;j++,k++)
{c[k]=b[j];
}
System.out.print("\nThe merged array is \n");
for(k=0;k<10;k++){
System.out.print(c[k]+" ");}
return;}
};//end class

Pg-40
OUTPUT:-
Enter 1-th value 1

Enter 2-th value 12

Enter 3-th value 13

Enter 4-th value 45

Enter 5-th value 56

Enter 6-th value 55


Enter 4 values for the second array

Enter 1-th value 44

Enter 2-th value 45

Enter 3-th value 464


Enter 4-th value 4564

The merged array is


1 12 13 45 56 55 44 45 464 4564

Variable Description:-

Name of the variable Datatype Purpose

i int Stores the no. of the 1st array


j int Stores the no. of the 2nd
array
k int Merge the both 1st and 2nd
array

Pg-41
Assignment No.: 17
Topic:- i) Largest and the smallest element.
ii) Product of odd numbers.
iii) Sum of the even numbers.

Pg-42
17)Write a Program to find from the following
data:17,20,24,29,16,87,19,52.
i) The largest and smallest element ;
ii) Product of the odd number ;
iii)Sum of the even numbers.

SOLUTION:-
import java.util.*;
class Q17X{
public static void main(String [] args)
{
int i,large,small,pro=1,sum=0;
int [] a={17,20,24,29,16,87,19,52};
large=a[0];
small=a[0];
for(i=0;i<a.length;i++) {
if(a[i]>large)
large=a[i];
if(a[i]<small)
small=a[i];

if(a[i]%2==1)
pro*=a[i];
else
sum+=a[i];
}

System.out.print("\nThe largest among the array is "+large+"\n The smallest is


"+small);
System.out.print("\nThe Product of odd numbers "+pro+" \n Sum of even "+sum);
return;

}
}

Pg-43
OUTPUT:-

The largest among the array is 87


The smallest is 16
The Product of odd numbers 814929
Sum of even 112

Variable Description:-

Name of the variable Datatype Purpose

i int Stores the no.


large int Stores the large no. among
them
small int Stores the small no. among
them
pro int Stores the product of the
odd no. among them
sum int Stores the sum of the even
no. among them

Pg-44
Assignment No.: 18
Topic:-i) Number of word present in the sentence
ii) number of letter present in the sentence

Pg-45
18) Write a program to input a sentence. Find and display the
following :
i) Number of words present in the sentence.
ii)Number of letters present in the sentence.
Assume that the sentence has neither include any digit following
nor a special character.

Solution :-
import java.util.*;

class word_sentences{
public static void main(String [] args)
{
String s;
int i,b;
Scanner ki=new Scanner(System.in);
System.out.print("\nEnter a sentence [DON\'T PUT . OR ? AT THE END OF THE
SENTENCE ]");
s=ki.nextLine();
for(i=0,b=0;i<s.length();i++)
{
if(s.charAt(i)==' ')
b++;//counting blank spaces
}//end for
/In a sentence no of words are 1 more than no of blankspaces/
/"I LOVE INDIA" the sentence has 2 blanks while 3 no of words/

System.out.print("1. No of words "+(b+1)+" and "+"\n2. The no of letters present in the


sentence is "+ (s.length()-b));
return;
}//end main
};//end class

Pg-46
OUTPUT:-
Enter a sentence [DON'T PUT . OR ? AT THE END OF THE SENTENCE ]
I love my school
1. No of words 5 and
2. The no of letters present in the sentence is 13

Variable Description:-

Name of the variable Datatype Purpose

i int Count the length of the


message
b int Count the blank space in the
message
s string Stores the message
Pg-47
Assignment No.: 19
Topic:-To accept a word/ String and display the new string

Pg-48

19)Write a program Java to accept a word/ a string


and display the new string after removing all the
vowels present in it.
Sample input: COMPUTER APPLICATION
Sample Output : CMPTR PPLCTNS

SOLUTION:-
class removal_of_vowels
{
public static void main(String[]args)throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter a String:");
StringBuffer s =new StringBuffer(br.readLine().toLowerCase());
int i;
for(i=0;i<s.length();i++)
{
if((s.charAt(i)=='a')||(s.charAt(i)=='e')||(s.charAt(i)=='i')||(s.charAt(i)=='o')||
(s.charAt(i)=='u')){
s.deleteCharAt(i);
--i;}//end if
}//end for
System.out.print(s);
return;
}//end main
};//end class

Pg-49
Output:-

Enter a String:
Bhishop Morrow
bhshp mrrw

Variable Description:-

Name of the variable Datatype Purpose


i int Stores the length of the
string
s String Stores the string

Pg-50
Assignment No.: 20
Topic:-To enter a string or sentence and display the longest word
and the length of the longest word

Pg-51
20) Write a program in JAVA to enter a string/ sentence &
display the longest word and the length of the longest word
present in the string.
Sample Input :"TATA FOOTBALL ACADEMY WILL PLAY
AGAINST MOHON BAGAN".
Sample Output : The longest word :FOOTBALL
The length of the word: 8

SOLUTION:-

import java.io.*;
import java.lang.*;
import java.util.*;
class longest_word
{
public static void main(String [] args)
{int i=0,max=0;
Scanner ki=new Scanner(System.in);
String s,st1 ="";

System.out.print("Enter the string to find out the longest word =>");


s=ki.nextLine();
String [] ar=s.split(" ");

for(i=0;i<ar.length;i++)
{
if(ar[i].length()>max)
{
max=ar[i].length();
st1=ar[i];
}

}//end for

System.out.println("The longest word "+st1+ " has "+max+" characters.");

return;
}

};

Pg-52

Output:-
Enter the string to find out the longest word =>TATA FOOTBALL ACADEMY PLAYED
AGAINST MOHAN BAGAN.
The longest word FOOTBALL has 8 characters.

Variable Description:-

Name of the variable Datatype Purpose

i int Stores the length of the


string
max int Stores the maximum length
from the string
s String Stores the whole string
entered by the user
st1 String Stores the longest string

Pg-53

Conclusion
Java has significant advantages not only as a commercial
language but also as a teaching language. It allows students
to learn object-oriented programming without exposing
them to the complexity of C++. It provides the kind of
rigorous compile-time error checking typically associated
with Pascal. It allows instructors to introduce students to
GUI programming, networking, threads, and other
important concepts used in modern-day software.

Java might well be a language that most computer science


departments could agree to use as an introductory
language. If so, we'll all benefit from once again having a
single dominant language in CS1.

Pg-54

Bibliography
 ICSE Computer Application
 APC Computer with BlueJ
 www.kboat.com.
Pg-55

Declaration

I, Priyam Saha, studying in class X-B-14 of BISHOP


MORROW SCHOOL, is solemnly declare that this Computer
Assignment is completed and presented by me and myself.

Signature of the student-

Date: - 03/06/2022

Signature of the Parents:-


Mother-

Father-

Subject Teacher’s Signature-

Marks-

External Teacher’s Signature-

Marks-

Pg-56
Pg-57

You might also like