1. Write a getInt() method that takes as input a String prompt and a Scanner, an
ID: 3565204 • Letter: 1
Question
1. Write a getInt() method that takes as input a String prompt and a Scanner, and returns an integer. This method prompts a user for an integer. If the entered value is an integer, then it is returned. If it is not an integer, then this method must re-prompt until an integer is entered.
2. Write a getLucasSequence() method that takes as input integer parameters p, q and n. Where p and q are Lucas parameters as de?ned above and n determines how many Lucas numbers are generated. This method returns an ArrayList of integers: Lpq(0),Lpq(1),Lpq(2),...,Lpq(n)
3. Write a checkSequence() method that takes as input an ArrayList of integers, identi?es the ?rst i that is greater than or equal to 2 for which Lpq(i) ? i^4 and prints out: i : Lpq(i) i^4 If there is no such i, then this method must print out
Explanation / Answer
import java.io.*;
class ret{
boolean check(string p,string q,string n){ // 1 part
for (int i = 0; i < p.length; i++){
char ch = p[i];
if (ch >= 48 && ch <= 57)
continue;
else
return false;
}
for (int i = 0; i < q.length; i++){
char ch = q[i];
if (ch >= 48 && ch <= 57)
continue;
else
return false;
}
for (int i = 0; i < n.length; i++){
char ch = n[i];
if (ch >= 48 && ch <= 57)
continue;
else
return false;
}
return true;
}
int[] getLucasSequence(p,q,n){ // 2 part
int[] l = new l[n];
l[0] = 0;
l[1] = 1;
for (int i = 2; i <= n; i++){
l[i] = p*l[i-1] - q*l[i-2];
}
return l;
}
boolean checkSequence(int[] l){ // 3 part
for (int i = 2; i < l.length; i++){
if (l[i] >= i^4)
return i;
}
return
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.