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

Write a program in java to read a string object consisting 300 characters or mor

ID: 3722894 • Letter: W

Question

Write a program in java to read a string object consisting 300 characters or more using index input Stream reader. The program should perform following operations. The String must have proper words and all kind of characters. Can you please use stringbuffer for this program?
1.Determine the length of the string
2.count the number of letters in the strings
3.count the number of numeric digits
4.Calculate the number of special character
5.Compute the ratio of the numeric to the total characters
6.Compute the ratio of space character to all special characters.
7.Find the position of the character (a) in the first occurrence.
8.Then find the position of the character (a) in the first 50 characters.
9.Find the position of (a) after the 15th character.
10.If the word on the first line starts with the character (a) then change to upper case.
11.Find the position of each ($).
12.If a line ends with a period. Count the number of lines with such construct.
13.Count the number of space on the last line. Write a program in java to read a string object consisting 300 characters or more using index input Stream reader. The program should perform following operations. The String must have proper words and all kind of characters. Can you please use stringbuffer for this program?
1.Determine the length of the string
2.count the number of letters in the strings
3.count the number of numeric digits
4.Calculate the number of special character
5.Compute the ratio of the numeric to the total characters
6.Compute the ratio of space character to all special characters.
7.Find the position of the character (a) in the first occurrence.
8.Then find the position of the character (a) in the first 50 characters.
9.Find the position of (a) after the 15th character.
10.If the word on the first line starts with the character (a) then change to upper case.
11.Find the position of each ($).
12.If a line ends with a period. Count the number of lines with such construct.
13.Count the number of space on the last line. Write a program in java to read a string object consisting 300 characters or more using index input Stream reader. The program should perform following operations. The String must have proper words and all kind of characters. Can you please use stringbuffer for this program?
1.Determine the length of the string
2.count the number of letters in the strings
3.count the number of numeric digits
4.Calculate the number of special character
5.Compute the ratio of the numeric to the total characters
6.Compute the ratio of space character to all special characters.
7.Find the position of the character (a) in the first occurrence.
8.Then find the position of the character (a) in the first 50 characters.
9.Find the position of (a) after the 15th character.
10.If the word on the first line starts with the character (a) then change to upper case.
11.Find the position of each ($).
12.If a line ends with a period. Count the number of lines with such construct.
13.Count the number of space on the last line.

Explanation / Answer

import java.io.*;
import java.util.*;
public class String_operations_example
{
public static void main(String args[]) throws Exception
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter your string:");
String s=br.readLine();
StringBuffer sb=new StringBuffer(s);
  
System.out.println("Length of the String:"+sb.length());
int no_of_letters=0;
for(int i=0;i<sb.length();i++)
if(Character.isLetter(sb.charAt(i)))
no_of_letters++;
System.out.println("no of letters in string:"+no_of_letters);
  
int no_of_digits=0;
for(int i=0;i<sb.length();i++)
if(Character.isDigit(sb.charAt(i)))
no_of_digits++;
System.out.println("no of digits in string:"+no_of_digits);
  
System.out.println("no of special characters:"+(sb.length()-no_of_letters-no_of_digits));
  
System.out.println(" ratio of the numeric to the total characters:"+(double)(no_of_letters*1.0/sb.length()));
  
int no_of_spaces=0;
for(int i=0;i<sb.length();i++)
if(sb.charAt(i)==' ')
no_of_spaces++;

double ratio=(double) no_of_spaces*1.0/(sb.length()-no_of_letters-no_of_digits);
System.out.println("ratio of space character to all special characters:"+ratio);
  
System.out.println("character 'a' has occured at position:"+(sb.indexOf("a")+1));
  
System.out.println("first position of 'a' in first fifty characters:"+(sb.substring(0, 50).indexOf('a')+1));
System.out.println("first position of 'a' in after 15th character:"+(sb.substring(15, sb.length()).indexOf('a')+15+1));  

if(sb.charAt(0)=='a')
sb=new StringBuffer(Character.toUpperCase(sb.charAt(0))+sb.substring(1));
  
System.out.println("positions of $ in the string are:");

for(int i=0;i<sb.length();i++)
if(sb.charAt(i)=='$')
System.out.print(i+" ");
System.out.println();
  
int no_of_periods=0;
for(int i=0;i<sb.length();i++)
if(sb.charAt(i)=='.')
no_of_periods++;
System.out.println("no of lines are:"+no_of_periods);
  
int prev_pos=0;
for(int i=0;i<sb.length()-1;i++)
if(sb.charAt(i)=='.')
prev_pos=i;
int spaces_in_last_line=0;
for(int i=prev_pos;i<sb.length()-1;i++)
if(sb.charAt(i)==' ')
spaces_in_last_line++;
  
System.out.println("no of spaces in last line:"+spaces_in_last_line);
  
}
  
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote