this my seems long, but is just a small method i need that requires the used of
ID: 650249 • Letter: T
Question
this my seems long, but is just a small method i need that requires the used of other methods wich i put in the bottom,
thank you, i will rate .
Exercise: Define a method
double[] rotate(int n, double[] list)
that rotates a list n places to the left, wrapping around at the start of the list, and assuming n is in the range zero to the length of the list. For example:
rotate(1, freqs("haskellisfun") ) ->
{0.0,0.0,0.0,8.33333,8.33333,0.0,8.33333,8.33333,0.0,8.33333,16.6667,0.0,8.33333,0.0,0.0,0.0,0.0,16.6667,0.0,8.33333,0.0,0.0,0.0,0.0,0.0,8.33333}
methods i did
static int lower(String str) {
int lowercase = 0;
for (int i = 0; i < str.length(); i++) {
if (Character.isLowerCase(str.charAt(i))) {
lowercase++;
}
}
return lowercase;
}
static int count(char c, String str) {
int counter = 0;
for (int i = 0; i < str.length(); i++) {
if (str.charAt(i) == c) {
counter++;
}
}
return counter;
}
static double percent(int num1, int num2) {
double a = num1;
double b = num2;
return ((a / b) * 100);
}
static double[] freqs(String str) {
double[] frequency = new double[26];
for (int i = 0; i < 26; i++) {
frequency[i] = percent(count(nat2let(i), str), lower(str));
}
return frequency; }
Explanation / Answer
Chegg removed the "Edit Point Total" feature and now no one is answering questions
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.