-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCoding_challenge_1.java
More file actions
57 lines (40 loc) · 1.45 KB
/
Coding_challenge_1.java
File metadata and controls
57 lines (40 loc) · 1.45 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
package Coding_challenge_1;
import java.util.Scanner;
public class Coding_challenge_1 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Text: ");
String text = input.nextLine();
// String text = "Congratulations! Today is your day. You're off to Great Places! You're off and away";
double letterCount = 0;
double wordCount = 0;
double sentencecount = 0;
char temp;
if(!text.isEmpty())
wordCount++;
for( int i = 0; i < text.length( ); i++ )
{
temp = text.charAt( i );
if(temp != ' ' && temp != '!' && temp != '?' && temp != '.' && temp != '\'')
letterCount++;
else if(temp == ' ')
wordCount++;
else if(temp != '\'')
sentencecount++;
}
double L = (letterCount/wordCount)*100;
double S = (sentencecount/wordCount)*100;
double Index = 0.0588 * L - 0.296 * S - 15.8;
System.out.println("Grade: "+ Math.round(Index));
// Sample output
// Text: Congratulations! Today is your day. You're off to Great Places! You're off and away!
// Grade: 3
// output code to debug, please disregard
// System.out.println("Letters: "+ letterCount);
// System.out.println("Words: "+ wordCount);
// System.out.println("sentencecount: "+ sentencecount);
// System.out.println("Lp100: "+ L);
// System.out.println("Sp100: "+ S);
// System.out.println("Grade: "+ Math.round(Index));
}
}