Question: Write a program that prompts for and reads in a line of text, and then performs the following tasks: - Outputs the number of characters
Write a program that prompts for and reads in a line of text, and then performs the following tasks: - Outputs the number of characters on the line. (Hint: The String class has a method named length() that returns the number of characters in a string.) - Outputs the number of words on the line. (Hint: Break up the line of text with the method split using 1 or more whitespaces as a delimiter (\\s+), and then output the size of the returned array.) - Outputs the longest word on the line. (Hint: The split method breaks-up the line of text into words (or tokens), and stores those words into an array. Search that array to find out the longest word.) - Outputs the words in ascending order. (Hint: The Arrays class has a method named sort that takes an array as an argument, and orders the elements of that array in ascending order.) Include a loop in the program that allows the user to repeat the above steps as often as (s)he/they wishes. Sample Input and Output: Programmer: Name of the programmer (your name) Course: COSC 211, W 22 Lab#: 2, part 1 Due date: 1-27-2022 Enter a line of text: Hello to all Number of characters: 12 Number of words: 3 Longest word: Hello Words in ascending order: Hello all to Do it again, yes (or no)? Yes Enter a line of text: The fat cat sat on the mat in front of the door Number of characters: 47 Number of words: 12 Longest word: front Words in ascending order: The cat door fat front in mat of on sat the the Do it again, yes (or no)? no
A number is prime if it has no divisor other than 1 and itself (see pages 191-192 of your textbook, and demo011822 from the class website). A prime number that can be written in the form of 2p 1 for some positive integer p is known as Mersenne prime (Google it if you want to learn more about Mersenne primes). Write a method named isPrime that takes a BigInteger as an argument and determines whether or not that BigInteger value is a prime number. The method returns true if the number is a prime, and false otherwise (see method primeBig in demo011822). public static boolean isPrime (BigInteger num) { } Write a program (a main method) that finds all Mersenne primes with p <= 100, and displays the output as shown in the sample input/output below. Your program will have a for-loop that iterates from 2 through100 (these are possible values for p). Each time through the loop it creates a BigInteger in the form of 2p 1 where p is the index of the loop, and then it calls the method isPrime to determine whether or not that value is a prime. If that value (2p 1) is a prime number, then it displays both the value of p and 2p 1 as shown below. Sample Input and Output: The output below is incomplete, see if you can compute the values for the missing row (or rows). Programmer: Name of the programmer (your name) Course: COSC 211, W 22 Lab#: 2, part 2 Due date: 1-27-2022 P 2^p 1 ---------------------------- 2 3 3 7 5 31 7 127 13 8191 17 131071 19 524287 31 2147483647
****** i need the java code ***
please use this eclipse *****
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
