Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need solution write a program the reads string from the user then count the nu

ID: 3636094 • Letter: I

Question

I need solution
write a program the reads string from the user then count the number of 't' characters and 'p' characters in a given string .
enter "yes" if you want to continue reading a string , otherwise enter "no"

my answer :
import java.util.*;
/**........................*/
Scanner input =new Scanner(System.in);
int countt = 0, countp = 0 ;
String s , s1;
System.out.println("Enter the String :");
s=input.nextLine();
for(int j=1;j<=s.length();j++)
{
for(int i=0;i<s.length();i++)
{
if(s.charAt(i)=='t')
countt++;
if(s.charAt(i)=='p')
countp++;
}//for2
System.out.println("Enter the String :");
s=input.nextLine();
}//for1
System.out.println("number of t characters :"+countt+" "+"number of p characters:"+countp);
}//main
}//class

Explanation / Answer

import java.util.*; class test { public static void main(String[] args) { Scanner input =new Scanner(System.in); int countt = 0, countp = 0 ; String s , s1; // s is the string to count 't' and 'p', while s1 is the 'yes' or 'no' answer System.out.println("Enter the String :"); s=input.nextLine(); do { // Loop through the entered string for(int i=0;i