Question

Write a program in java to read a string object consisting 300 characters or more using...

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.(Use String class methods).


a, Determine the length of the string count the number of letters in the strings

, count the number of numeric object

d. Calculate the number of special character

e. Compute the ratio of the numeric to the total

f. Compute the rate of space character to all special characters.

g. Find the position of character in the first occurrence.

h. Then find the position of this character in the first 50 characters.

I. Find the position of (a) after the 15th character.

j. If the word on the first starts with a change to upper case.

k. Find the position of each ($).

If a line ends with a period. Count the number of lines with such construct.

Count the number of space on the last line.

Please write it in a simple way.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.*;

import java.lang.*;

import java.io.*;

import java.util.Scanner;

class Exercise38

{

public static void main(String[] args)//throws Exception

{

Scanner sc=new Scanner(System.in);  

  

System.out.println("Enter a string:");

String test=sc.next();

System.out.println("String is:"+test);

char[] ch = test.toCharArray();

char dollar='$';

int letter = 0;

int space = 0;

int num = 0;

int other = 0;

int d=0;

for(int i = 0; i < test.length(); i++){

if(Character.isLetter(ch[i])){

letter ++ ;

}

else if(Character.isDigit(ch[i])){

num ++ ;

}

else if(Character.isSpaceChar(ch[i])){

space ++ ;

}

else if(ch[i]==dollar){

d++ ;

}

else{

other ++;

}

}

double ratio=(num/letter);

System.out.println("The string length is: "+test.length());

System.out.println("letter: " + letter);

System.out.println("space: " + space);

System.out.println("number: " + num);

System.out.println("Dollar " + d);

System.out.println("Ratio of number to letters= " + ratio);

}

};

Add a comment
Know the answer?
Add Answer to:
Write a program in java to read a string object consisting 300 characters or more using...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 2. Searching a String: Write a MIPS assembly language program to do the following: Read a...

    2. Searching a String: Write a MIPS assembly language program to do the following: Read a string and store it in memory. Limit the string length to 100 characters. Then, ask the user to enter a character. Search and count the number of occurrences of the character in the string. The search is not case sensitive. Lowercase and uppercase letters should be equal. Then ask the user to enter a string of two characters. Search and count the number of...

  • write in python String: A sequence of characters enclosed within single or double quotes

    write in pythonString: A sequence of characters enclosed within single or double quotes. A string can include any character, including special characters and spaces. Examples: "Hello World!", 'I have $250 cash and a credit card.' Note: Each character in a string falls in a specific position, so we can assign an index (numbering) to each character. Such assignment helps us to perform mathematical operations on strings. Operations: * finding characters by position, length of string, concatenating, replicating, slicing * Back slashes for escape sequences: new...

  • Write a program that reads in a sentence of up to 100 characters and outputs the...

    Write a program that reads in a sentence of up to 100 characters and outputs the sentence with spacing corrected and with letters corrected for capitalization. In other words, in the output sentence, all strings of two or more blanks should be compressed to a single blank. The sentence should start with an uppercase letter but should contain no other uppercase letters. Do not worry about proper names; if their first letters are changed to lowercases, that is acceptable. Treat...

  • Write a Java program called Histogram.java that displays a list of distinct characters in an input...

    Write a Java program called Histogram.java that displays a list of distinct characters in an input tile and the occurrence of each eharacte. Your iogram should 1ead an input file name from a use. After that, your program should read characters in the file and display a list of distinct characters and their occurTeces. Finally, your program should draw a veril bafo the occuences For the assignment, your program has.to display the result exactly as the sample run. For instance,...

  • Python program. Character-Analysis Program Problem Statement: Design a program - IN PYTHON - that asks the...

    Python program. Character-Analysis Program Problem Statement: Design a program - IN PYTHON - that asks the user to enter a string. The string will then be displayed back to the user. This is followed by determining the number of alphabetic characters, numeric characters, lower_case letters, upper_case letters, whitespace characters, and then displaying them. The user should be given additional chances to enter additional strings, and each time a string is entered, the above process is to be performed. The inputting...

  • 14.3: More Sentences Write a program that allows a user to enter a sentence and then...

    14.3: More Sentences Write a program that allows a user to enter a sentence and then the position of two characters in the sentence. The program should then report whether the two characters are identical or different. When the two characters are identical, the program should display the message: <char> and <char> are identical! Note that <char> should be replaced with the characters from the String. See example output below for more information. When the two characters are different, the...

  • PLEASE WRITE SIMPLE JAVA PROGRAM AND ALSO EXPLAIN THE LOGIC. Given a string, print the first...

    PLEASE WRITE SIMPLE JAVA PROGRAM AND ALSO EXPLAIN THE LOGIC. Given a string, print the first word which has its reverse word further ahead in the string. Input Format: A string of space separated words, ending with a 's'. Conditions ; Each string ends with a $ character. All characters in the string are either spaces. $ or lower case English alphabets, Output Format : In a single line pent either . The first word from the start of the...

  • Objectives: Use strings and string library functions. Write a program that asks the user to enter...

    Objectives: Use strings and string library functions. Write a program that asks the user to enter a string and output the string in all uppercase letters. The program should then display the number of white space characters in the string. You program should run continuously until the user enters an empty string. The program must use the following two functions: A function called count_spaces that counts the number of white spaces inside a string. int count_space(char str[]); which tell you...

  • JAVA STRINGS AND CHARACTERS - USE SIMPLE CODING 1. Write a program that takes a string...

    JAVA STRINGS AND CHARACTERS - USE SIMPLE CODING 1. Write a program that takes a string of someone's full name and prints it out last name first. You may use the available string manipulation methods. Example: "George Washington" "Washington, George" 2. Write a program that will take a string of someone's full name, and break it into separate strings of first name and last name, as well as capitalize the first letter of each. Example: "joseph smith", "Joseph" "Smith"

  • Write an LC-3 program (starting at memory location 0x3000) to take a string as input and...

    Write an LC-3 program (starting at memory location 0x3000) to take a string as input and then output information about this string. The end of the string will be denoted with the "#" character. Once the "#" has been found, output the following in order: 1) The letter “u” followed by the number of uppercase letters in the string (A-Z) 2) The letter “l” followed by the number of lowercase letters in the string (a-z) 3) The letter “n” followed...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT