-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTheEnd.java
More file actions
34 lines (31 loc) · 970 Bytes
/
Copy pathTheEnd.java
File metadata and controls
34 lines (31 loc) · 970 Bytes
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
/*
Given a string, return a string length 1 from its front, unless front is false,
in which case return a string length 1 from its back. The string will be non-empty.
*/
package codingbat;
import java.util.Scanner;
public class TheEnd {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String str="";
char res;
boolean bool=true;
for(int i = 0; i < 10; i++){
System.out.println("Enter a string: ");
str = sc.nextLine();
bool = generateBool(bool);
System.out.println(logic(str, bool));
}
}
public static boolean generateBool(boolean bool){
return (Math.random() < 0.5);
}
public static char logic(String str, boolean bool){
if(bool == true){
return str.charAt(0);
}
else{
return str.charAt(str.length()-1);
}
}
}