You are on page 1of 5

JAVA LAB FAT

NAME: - ANIKET MISHRA


REGISTRATION NO: - 19BCE2062
DATE: - 03-11-2020
COURSE CODE: - CSE1007

m
er as
COURSE TITLE: - JAVA PROGRAMMING

co
eH w
o.
rs e SLOT: -L39+L40
ou urc
o

1. Write a java code to count and show the Magic words in an


aC s

array of string
v i y re

(i) Sort(ascending) the given array by ignoring the cases(treat


ed d

upper and lower case as same) [10 Mark]


ar stu

(ii) Sort(ascending) the given array after remove vowels in


each items. [25 Mark]
sh is
Th

Magic Word: If any index item has not changed its original
inputted index item after performed (i) and (ii) operation.
Note: Array inputs must be read from the file. [5 Mark]
Final Output: Your array contains four magic words bush,
BUSH, Seed and vain are magic words
Code:

This study source was downloaded by 100000827365976 from CourseHero.com on 06-06-2021 23:45:13 GMT -05:00

https://www.coursehero.com/file/89508815/SOLN-FATpdf/
import java.util.*;
class magic
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.print("Enter number of Strings you want
to enter: ");
int te=0,n=sc.nextInt();
String o[]=new String[n];
String op1[]=new String[n];
String op2[]=new String[n];
String magicwords[]=new String[n];

m
int pos1[]=new int[n];

er as
int pos2[]=new int[n];

co
eH w
String temp="";

o.
temp = sc.nextLine();rs e
for(int i = 0; i < n; i++)
ou urc
{
System.out.print("Enter string at index
o

["+i+"]: ");
aC s

o[i] = sc.nextLine();
v i y re

op1[i]=op2[i]=o[i];
pos1[i]=i;
pos2[i]=i;
ed d

}
ar stu

String s,ne="";
char ch;
sh is

for(int i = 0; i < n; i++)


{
Th

ne="";
for(int j = 0; j < op2[i].length(); j++)
{
s=op2[i].toLowerCase();
ch=s.charAt(j);
if(ch=='a' ||ch=='e' ||ch=='i' ||ch=='o'
||ch=='u' )
{
}

This study source was downloaded by 100000827365976 from CourseHero.com on 06-06-2021 23:45:13 GMT -05:00

https://www.coursehero.com/file/89508815/SOLN-FATpdf/
else
{
ne=ne+op2[i].charAt(j);
}
}op2[i]=ne;
}
for (int i = 0; i < n; i++)
{
for (int j = i + 1; j < n; j++)
{
if (op1[i].compareToIgnoreCase(op1[j])>0)
{
temp = op1[i];

m
op1[i] = op1[j];

er as
op1[j] = temp;

co
eH w
te=pos1[i];

o.
pos1[i]=pos1[j];
rs e
pos1[j]=te;
ou urc
}
if (op2[i].compareToIgnoreCase(op2[j])>0)
o

{
aC s

temp = op2[i];
v i y re

op2[i] = op2[j];
op2[j] = temp;
te=pos2[i];
ed d

pos2[i]=pos2[j];
ar stu

pos2[j]=te;
}
sh is

}
}int c=0;
Th

for(int i = 0; i < n; i++)


{
if(pos1[i]==i && pos2[i]==i)
{
magicwords[c++]=o[i];
}
}
System.out.println("Your array has "+c+" magic
words.");

This study source was downloaded by 100000827365976 from CourseHero.com on 06-06-2021 23:45:13 GMT -05:00

https://www.coursehero.com/file/89508815/SOLN-FATpdf/
for(int i = 0; i < c; i++)
{
System.out.print(magicwords[i]+",");
}System.out.print(" are magic words.");
}
}

Test Case 1:

m
er as
co
eH w
o.
rs e
ou urc
o
aC s
v i y re
ed d

Test Case 2:
ar stu
sh is
Th

This study source was downloaded by 100000827365976 from CourseHero.com on 06-06-2021 23:45:13 GMT -05:00

https://www.coursehero.com/file/89508815/SOLN-FATpdf/
m
er as
co
eH w
Test Case 3:

o.
rs e
ou urc
o
aC s
v i y re
ed d
ar stu
sh is
Th

This study source was downloaded by 100000827365976 from CourseHero.com on 06-06-2021 23:45:13 GMT -05:00

https://www.coursehero.com/file/89508815/SOLN-FATpdf/
Powered by TCPDF (www.tcpdf.org)

You might also like