0% found this document useful (0 votes)
30 views6 pages

Oopm Experiment 7 46

The document contains 3 Java programs that perform different tasks: 1. The first program counts the number of times "Engineering" occurs in a string and finds the longest word. It replaces occurrences of these strings in the output. 2. The second program checks if a user-input string is a palindrome by reversing it and comparing. 3. The third program sorts a list of names entered by the user in alphabetical order and displays the result.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views6 pages

Oopm Experiment 7 46

The document contains 3 Java programs that perform different tasks: 1. The first program counts the number of times "Engineering" occurs in a string and finds the longest word. It replaces occurrences of these strings in the output. 2. The second program checks if a user-input string is a palindrome by reversing it and comparing. 3. The third program sorts a list of names entered by the user in alphabetical order and displays the result.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

OOPM EXPERIMENT 07

INPUT 07 A:

//NAME: Aarushi Jha //

//CLASS: SE CMPNA //

//ROLL NO: 46 //

import java.util.Scanner;

public class EXP7A{

public static void main(String[] args) {

Scanner sc =new Scanner(System.in);

System.out.println("Enter Document:");

String doc = sc.nextLine();

String arr[]=doc.split(" ");

int count=0;

String maxword=" ";

for(int i=0;i<arr.length;i++)

if(arr[i].equals("Engineering"))

count++;

if(arr[i].length()>maxword.length())

maxword=arr[i];

System.out.println("\nEngineering Occurs "+count+" times");

System.out.println("The longest word is "+maxword+" with length "+maxword.length());


String newdoc = doc.replace("Engineering","Engg.");

newdoc= newdoc.replace(maxword,"*"+maxword+"*");

System.out.println("Modified Document:\n"+newdoc);

OUTPUT:
java -cp /tmp/lO9wWnrGz4 EXP7A

Enter Document:

SFIT has five UG Programs and two PG Programs in the most coveted disciplines considering both
industrial need and public preference. These courses would lead to award of the Degree of Bachelor
of Engineering (B.E.) in Computer Engineering, Electronics & Telecommunication Engineering,
Information Technology, Electrical Engineering and Mechanical Engineering and Master of
Engineering (M.E.) as well as Ph.D. (Technology) in Computer Engineering and Electronics &amp;
Telecommunication Engineering.

Engineering Occurs 5 timesThe longest word is Telecommunication with length 17Modified


Document:

SFIT has five UG Programs and two PG Programs in the most coveted disciplines considering both
industrial need and public preference. These courses would lead to award of the Degree of Bachelor
of Engg. (B.E.) in Computer Engg., Electronics & *Telecommunication* Engg., Information
Technology, Electrical Engg. and Mechanical Engg. and Master of Engg. (M.E.) as well as Ph.D.
(Technology) in Computer Engg. and Electronics &amp; *Telecommunication* Engg..
INPUT 07 B:

//NAME:Aarushi Jha//

//ROLL NO:46 //

//CLASS: SE CMPNA//

import java.util.Scanner;

public class Exp_7b

public static void main(String[] args)

Scanner sc=new Scanner(System.in);

System.out.println("Enter a string which you want to check:");

String str=sc.nextLine();

StringBuffer s1=new StringBuffer(str);

StringBuffer s2=new StringBuffer(s1);

s1.reverse();

System.out.println("Given string is:"+s2);

System.out.println("Reversed string is:"+s1);

if(String.valueOf(s1).compareTo(String.valueOf(s2))==0)

System.out.println(s2+" is Palindrome");

else
{

System.out.println(s2+" is not a Palindrome");

OUTPUT:
java -cp /tmp/EEIj3ttVCO Exp_7b

Enter a string which you want to check:

malayalam

Given string is: malayalam

Reversed string is: malayalam

malayalam is Palindrome
INPUT 07 C:

//NAME: Aarushi Jha//

//CLASS: SE CMPNA //

//ROLL NO: 46 //

import java.util.*;

public class StudentNamesSorter {

public static void main(String[] args) {

// Create a Vector to store the names

Vector<String> names = new Vector<String>();

// Read five names from the command line and add them to the Vector

Scanner scanner = new Scanner(System.in);

for (int i = 0; i < 5; i++) {

System.out.print("Enter a name: ");

String name = scanner.nextLine();

names.add(name);

// Sort the names in alphabetical order

Collections.sort(names);

// Display the sorted list using Enumeration interface

Enumeration<String> enumeration = names.elements();

System.out.println("Sorted list of names:");

while (enumeration.hasMoreElements()) {

System.out.println(enumeration.nextElement());

}
}

OUTPUT:
java -cp /tmp/0f04aEzY08 StudentNamesSorter

Enter a name: Aarushi

Enter a name: Arti

Enter a name: Shruti

Enter a name: Jenica

Enter a name: Carol

Sorted list of names:

Carol

Jenica

Shruti

Arti

Aarushi

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy