Professional Documents
Culture Documents
m
er as
COURSE TITLE: - JAVA PROGRAMMING
co
eH w
o.
rs e SLOT: -L39+L40
ou urc
o
array of string
v i y re
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
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
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)