-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheng_piglatin.java
More file actions
97 lines (89 loc) · 2.98 KB
/
eng_piglatin.java
File metadata and controls
97 lines (89 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class eng_piglatin {
public static void main(String args[])throws Exception
{
Scanner sc=new Scanner(System.in);
char[] data =new char[100];
try
{
File f =new File("English_words.txt");
File f1=new File("PigLatin_words.txt");
FileWriter fw =new FileWriter("English_words.txt");
FileWriter fw_1=new FileWriter("PigLatin_words.txt");
System.out.println("Enter the number of English Words : ");
int n=sc.nextInt();
String English_word;
System.out.println("Enter the English Words : ");
for(int i=0;i<n;i++)
{
English_word=sc.next();
fw.write(English_word);
fw.write("\n");
char [] ch=English_word.toCharArray();
if((ch[0]=='a'||ch[0]=='e'||ch[0]=='i'||ch[0]=='o'||ch[0]=='u') && (ch[1]=='a'||ch[1]=='e'||ch[1]=='i'||ch[1]=='o'||ch[1]=='u'))
{
String new_pigLatin = English_word+"ay";
fw_1.write(new_pigLatin);
fw_1.write("\n");
}
else if(ch[0]=='a'||ch[0]=='e'||ch[0]=='i'||ch[0]=='o'||ch[0]=='u')
{
String new_pigLatin = English_word+"way";
fw_1.write(new_pigLatin);
fw_1.write("\n");
}
else if((ch[0]!='a'||ch[0]!='e'||ch[0]!='i'||ch[0]!='o'||ch[0]!='u') && (ch[1]=='a'||ch[1]=='e'||ch[1]=='i'||ch[1]=='o'||ch[1]=='u'))
{
int l=English_word.length();
String new_word = "";
for(int j = 1; j<l; j++)
{
new_word = new_word + English_word.charAt(j);
}
new_word = new_word + English_word.charAt(0);
String new_pigLatin = new_word + "ay";
fw_1.write(new_pigLatin);
fw_1.write("\n");
}
else if((ch[0]!='a'||ch[0]!='e'||ch[0]!='i'||ch[0]!='o'||ch[0]!='u') && (ch[1]!='a'||ch[1]!='e'||ch[1]!='i'||ch[1]!='o'||ch[1]!='u'))
{
int l=English_word.length();
String new_word = "";
for(int j = 2; j<l; j++)
{
new_word = new_word + English_word.charAt(j);
}
new_word = new_word + English_word.charAt(0) + English_word.charAt(1);
String new_pigLatin = new_word + "ay";
fw_1.write(new_pigLatin);
fw_1.write("\n");
}
}
fw.close();
fw_1.close();
FileReader fr = new FileReader("English_words.txt");
FileReader fr_1=new FileReader("PigLatin_words.txt");
BufferedReader br=new BufferedReader(fr);
BufferedReader br_1=new BufferedReader(fr_1);
System.out.println("---Display ENGLISH Words---");
FileReader fr1=new FileReader("English_words.txt");
fr1.read(data);
System.out.println(data);
fr1.close();
System.out.println("\n"+"---Display PIGLATIN Words---");
FileReader fr2=new FileReader("PigLatin_words.txt");
fr2.read(data);
System.out.println(data);
fr2.close();
}
catch(FileNotFoundException e)
{
System.out.println("The specified file does not exist...");
}
}
}