-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBye.java
More file actions
47 lines (41 loc) · 1.13 KB
/
Copy pathBye.java
File metadata and controls
47 lines (41 loc) · 1.13 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
package com.example.Bye;
public class Bye {
public void pigLatin(String n){
String a = "";
for (int i = 1; i <= n.length()-1; i++){
a += n.charAt(i);
}
a += n.charAt(0);
a += "ay";
System.out.println(a);
}
public void replace(String n, char m){
for (int i = 0; i <= n.length()-1; i++){
if (n.charAt(i) == m){
System.out.println("$");
}
else{
System.out.println(n.charAt(i));
}
}
}
public void longest(String n[]){
int max = n[0].length();
int pos = 0;
for (int i = 0; i <= n.length-1; i++){
if (n[i].length() > max){
pos = i;
max = n[i].length();
}
}
System.out.println(n[pos]);
}
public static void main(String[]args){
Bye runner = new Bye();
String a = "pig";
String b[] = {"hi", "hello", "bye"};
runner.pigLatin(a);
runner.replace("hello",'l');
runner.longest(b);
}
}