***change java code to pseudocode**** import java.io.*; import java.util.*; impo
ID: 3687828 • Letter: #
Question
***change java code to pseudocode****
import java.io.*;
import java.util.*;
import java.lang.*;
public static boolean isDNAIter(String str) {
int index,n;
char ch;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println(“enter index:”);
index = br.readLine();
System.out.println(“Enter no of indexes:”);
n = br.readLine();
for(index : 1 to n) {
ch = str.charAt(index);
if(ch == ‘A’ || ch==’T’ || ch==’G’ || ch==’C’)
return true;
else return false;
}
}
public static boolean isDNARec(String str) {
int index;
char ch;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
Systrm.out.println(“enter index:”);
index = br.readLine();
ch = str.charAt(index);
if(ch == ‘A’ || ch==’T’ || ch==’G’ || ch==’C’)
return true;
else return false;
boolen isDNARec(String str) +1;
}
public static int lastIndexSubStringMatch(String key,String target,int index) {
Boolean f;
int n;
int t;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println(“Enter no of indexes:”);
n= br.readLine();
for(index: 1 to n) {
f = key.matches(target,index);
if(f==”true”) {
t=key.lastIndexOf(target);
return t;
}
else return -1;
}
}
public static int countSubStringMatchIter(String key,String target) {
int count = 0;
int lastIndex =0;
while (lastIndex!=-1) {
lastIndex= str.index(key,target);
if(lastIndex !=-1) {
count = count++;
lastIndex + = key.length();
}
}
return count;
}
public static int countSubStringMatchRec(String key,String target) {
int count = 0;
int index;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
Syste.out.println(“Enter index:”);
index = br.readLine();
if(key.length() <4)
return 0;
else
{ if(key.substring(index) == target) {
count = count ++;
return countSubStringMatchRec(key.substring(index),target) +1; }
else return countSubStringMatchRec(key.substring(index),target);
}
return count;
}
public class DNA {
public static void main(String args[]) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int ch;
System.out.println(“Enter choice:”);
ch = br.readLine();
string key,target;
System.out.println(“Enter string”);
key = br.readLine();
System.out.println(“Enter substring”);
target = br.readLine();
switch(ch) {
case 1: System.out.println(“DNA - Iteration”);
String str;
System.out.println(“Enter string”);
str = br.readLine();
boolean isDNAIter(String str);
break;
case 2: System.out.println(“DNA – Recursion”);
String str;
System.out.println(“Enter string”);
str = br.readLine();
boolean isDNAREC(String str);
break;
case 3: System.out.println(“Last index of substring match”);
int index;
System.out.println(“Enter index”);
index = br.readLine();
int lastIndexSubStringMatch(String key,String target,ont index);
System.out.println(“Last index:” + t );
break;
case 4: System.out.println(“Counting substrings - Iteration”);
int countSubStringMatchIter(String key,String target);
System.out.println(“count:” +count);
break;
case 5: System.out.println(“Counting substrings – Recursion”);
int countSubStringMatchRec(String key,String target);
System.out.println(“count:” +count);
break;
}
}
}
Explanation / Answer
pseudocode is set of instructions .. which explained in a simple way rather than writing full code ...
public static boolean isDNAIter(String str) {
int index,n;
char ch;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
Read index;
read 'n' number of indexes
for(index : 1 to n) {
ch = str.charAt(index);
if(ch == ‘A’ || ch==’T’ || ch==’G’ || ch==’C’)
return true;
else return false;
}
}
public static boolean isDNARec(String str) {
int index;
char ch;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
read index;
ch = str.charAt(index);
if(ch == ‘A’ || ch==’T’ || ch==’G’ || ch==’C’)
return true;
else return false;
boolen isDNARec(String str) +1;
}
public static int lastIndexSubStringMatch(String key,String target,int index) {
read index;
for(index: 1 to n) {
f = key.matches(target,index);
if(f==”true”) {
t=key.lastIndexOf(target);
return t;
}
else return -1;
}
}
public static int countSubStringMatchIter(String key,String target) {
int count = 0;
int lastIndex =0;
while (lastIndex!=-1) {
lastIndex= str.index(key,target);
if(lastIndex !=-1) {
count = count++;
lastIndex + = key.length();
}
}
return count;
}
public static int countSubStringMatchRec(String key,String target) {
int count = 0;
int index;
read index;
if(key.length() <4)
return 0;
else
{
if(key.substring(index) == target) {
count = count ++;
return countSubStringMatchRec(key.substring(index),target) +1;
}
else return countSubStringMatchRec(key.substring(index),target);
}
return count;
}
public class DNA {
main() {
int ch;
read choice;
string key,target;
read key value;
read substring;
switch(ch) { //switch case
case 1: print iteration;
String str;
read str;
boolean isDNAIter(String str);
break;
case 2: print recursion;
String str;
read str;
boolean isDNAREC(String str);
break;
case 3: peint index of last substring
int index;
read index;
int lastIndexSubStringMatch(String key,String target,ont index);
print lasrIndex;
break;
case 4: print substring count;
int countSubStringMatchIter(String key,String target);
print count;
break;
case 5:
int countSubStringMatchRec(String key,String target);
print count;
break;
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.