Can someone help me out with this?
You are given a program that receives four lines in the below format, and stores them in str1, str2, str3, and num1.
This is not a very long sentence. is long 4
Expand this program to:
[first character][last character]
Search str1 for str2,
Compare str2 and str3 and
Find the str2 in str1, and
This is not a very long sentence. er long 4
The output will be:
This is not a v y long sentence.
Below is the list of methods that you might need
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
String str1 = scnr.nextLine();
String str2 = scnr.nextLine();
String str3 = scnr.nextLine();
int num1 = scnr.nextInt();
// Write your code below.
}
}
JAVA CODE
============================================================================================
package hello;
import java.util.*;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method
stub
Scanner scnr = new
Scanner(System.in);
String str1 =
scnr.nextLine();
String str2 =
scnr.nextLine();
String str3 =
scnr.nextLine();
int num1 = scnr.nextInt();
//print this line only if num1 is
higher than 0: "Num1 is higher than 0!"
//print this line only if num1 is
0: "Num1 equals to 0!"
//And otherwise,
print: ""Num1 is lower than 0!"
if(num1>0)
System.out.println("Num1 is higher than 0!");
else if(num1==0)
System.out.println("Num1 equals to 0!");
else
System.out.println("Num1 is lower than 0!");
if(str1.length()<0 ||
str2.length()<0)
System.out.println( "Error! Analysis is not possible!");
else if(str1.length()<5
&& (str1.contains(str2)==true))
System.out.println("Barely a sentence but had the word!");
else if(str1.length()<5
&& (str1.contains(str2)==false))
System.out.println("Barely a sentence and DID NOT have the
word!");
else if(str1.length()<20
&& (str1.contains(str2)==true))
System.out.println("A sentence and had the
word!");
else if(str1.length()<20
&& (str1.contains(str2)==false))
System.out.println("A sentence and
DID NOT have the word!");
else
System.out.println("Sentence is too long for analysis.");
//Prints the first and last
character of str1 in the below format:
//[first character][last
character]
System.out.println("["+str1.charAt(0)+"]["+str1.charAt(str1.length()-1)+"]");
//Search str1 for str2
if(str1.contains(str2))
System.out.println("Found it!");
//Compare str2 and str3
if(str2.compareTo(str3)>0)
System.out.println(str2);
else
if(str2.compareTo(str3)<0)
System.out.println(str3);
else
System.out.println("They are equal!");
//Find the str2 in str1
String s[]=str1.split(str2);
for(String k:s)
System.out.println(k);
}
}
============================================================================================
Output
Can someone help me out with this? You are given a program that receives four lines...
From the Tony Gaddis text, the chapter on C-String and Class String: String Length: Write a Function that passes in a C-String and using a pointer determine the number of chars in the string. Data: “This is a test string for string length” Prt String Backwards: Write a Function that passes in a C-String and prints the string backwards. Data: “This is a test string for string backwards” replaceSubstring: Write a Function that accepts three C-Strings – str1,...
SCREENSHOTS ONLY PLEASE!!! DON'T POST ACTUAL CODE PLEASE LEAVE A SCREENSHOT ONLY! ACTUAL TEXT IS NOT NEEDED!!! mystring.h: //File: mystring1.h // ================ // Interface file for user-defined String class. #ifndef _MYSTRING_H #define _MYSTRING_H #include<iostream> #include <cstring> // for strlen(), etc. using namespace std; #define MAX_STR_LENGTH 200 class String { public: String(); String(const char s[]); // a conversion constructor void append(const String &str); // Relational operators bool operator ==(const String &str) const; bool operator !=(const String &str) const; bool operator >(const...
Please help!! These are the errors I'm getting ... string_2_set - << Back Log out 1-def string_2_set(str): 2 Given a string, split it into words (based on whitespace). For each word, remove the first and last letters from the word, and insert the pair (as a two-character word) into the set. d = set() #empty set str2 -str , split(" ") #split string with space first = str2[0][0] + str2[0] [len(str2[0])-1] #first pair if(len(str2[1]) > 1): If any word is...
def cleanedup(s): alphabet = 'abcdefghijklmnopqrstuvwxyz#' cleantext = '' for character in s.lower(): if character in alphabet: cleantext += character else: cleantext += ' ' return cleantextlinecount=0maxlength=0with open('elon-musk.txt') as text: for line in text: linecount+=1 length=len(line.split()) if length>maxlength: maxline=line maxlength=length print('number of tweets:',linecount) print('Tweet with max number of words:', maxline) tweets={}with open('elon-musk.txt') as text: for line in text: for word in cleanedup(line).split(): ...
In python, please help me fill in these functions given their limitations. Please use for loops. def palindrome(x): """ For a given string, determine if the string is a palindrome. (The same forward and back) Input: String of any size (including empty) Return: Boolean (True if palindrome, False otherwise) Limitation: You must use a loop. Only function allowed to be used is len (if needed). Cannot use "in" besides "for var in container" """ pass def getCount(char, strng): """ Get...
CSC Hw Problems. Any help is appreciated I dont know where to start let alone what the answers are. Your assignment is to write your own version of some of the functions in the built-in <string.h> C library. As you write these functions, keep in mind that a string in C is represented as a char array, with the '\0' character at the end of the string. Therefore, when a string is passed as a parameter, the length of the...
Hi, it's C++ question. Only can use <iostream> and <fstream>libraries Please help me, thanks Question Description: For this project you will write a program to: a) read-in the 10 first names from a file (the file is a priori given to have exactly 10 entries, of a maximum length of 8 letters each) into a 2-dimensional character array, b) output the names to the terminal with each one preceded by a number indicating its original order in the list, c)...
hey dear i just need help with update my code i have the hangman program i just want to draw the body of hang man when the player lose every attempt program is going to draw the body of hang man until the player lose all his/her all attempts and hangman be hanged and show in the display you can write the program in java language: this is the code bellow: import java.util.Random; import java.util.Scanner; public class Hangmann { //...
This looks long but it is easy just having some trouble please help out thank you. Find and fix all syntax and semantic errors which prevent the program from compiling. Find and fix all logical errors which cause the program to crash and/or produce unexpected results. In addition to making sure the code compiles, we have one final method which we need to complete. There is a method in the code, printAll, which is responsible for printing out the entirety...
HELLO EXPERTS, I need a code for this 4 questions.... it's make me crazy now... could you guys help me please? it's java Given two strings, word and a separator sep, return a big string made of count occurrences of the word, separated by the separator string. repeatSeparator("Word", "X", 3)- "WordXWordXWord" repeatSeparator("This", "And", 2)- "ThisAndThis" repeatSeparator("This", "And", 1)- "This"| For example: Result Test System.out.println(repeatSeparator("Pa", "Tn", 4)); PaTnPaTnPaTnPa Consider the series of numbers beginning at start and running up to but...