Question

I need to make this into a Java Code: Write a Java program that asks the...

I need to make this into a Java Code:

Write a Java program that asks the user for four words: word1 word2 word3 word4.

Your prompts to the user must be:

Enter 4 words:

Output word1 and the length of word1 and the position of the character 'h' in word1
Output word2 and the length of word2 and the position of the character 'i' in word2
Output word3 and the length of word3 and the position of the substring "hi" in word3
Output word4 and the length of word4 and the position of the substring "bee" in word4

Sample runs would look like:

Enter 4 words:
she smiles third frisbee
Word 1 = "she" Length = 3 position of 'h' = 1
Word 2 = "smiles" Length = 6 position of 'i' = 2
Word 3 = "third" Length = 5 position of "hi" = 1
Word 4 = "frisbee" Length = 7 position of "bee" = 4

or

Enter 4 words:
shoe shoe chime wallabees
Word 1 = "shoe" Length = 4 position of 'h' = 1
Word 2 = "shoe" Length = 4 position of 'i' = -1
Word 3 = "chime" Length = 5 position of "hi" = 1
Word 4 = "wallabees" Length = 9 position of "bee" = 5

Please make sure to end each line of output with a newline.

Please note that your class should be named Words.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
import java.util.Scanner;

public class Words {
    public static void main(String[] args) {
        Scanner scnr = new Scanner(System.in);
        System.out.println("Enter 4 words:");

        String word1, word2, word3, word4;
        word1 = scnr.next();
        word2 = scnr.next();
        word3 = scnr.next();
        word4 = scnr.next();

        System.out.println("Word 1 = \""+word1+"\" Length = "+word1.length()+" position of 'h' = "+word1.indexOf("h"));
        System.out.println("Word 2 = \""+word2+"\" Length = "+word2.length()+" position of 'i' = "+word2.indexOf("i"));
        System.out.println("Word 3 = \""+word3+"\" Length = "+word3.length()+" position of \"hi\" = "+word3.indexOf("hi"));
        System.out.println("Word 4 = \""+word4+"\" Length = "+word4.length()+" position of \"bee\" = "+word4.indexOf("bee"));
    }
}

Add a comment
Know the answer?
Add Answer to:
I need to make this into a Java Code: Write a Java program that asks the...
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
  • //I NEED THE PROGRAM IN C LANGUAGE!// QUESTION: I need you to write a program which...

    //I NEED THE PROGRAM IN C LANGUAGE!// QUESTION: I need you to write a program which manipulates text from an input file using the string library. Your program will accept command line arguments for the input and output file names as well as a list of blacklisted words. There are two major features in this programming: 1. Given an input file with text and a list of words, find and replace every use of these blacklisted words with the string...

  • Today you are to write a Java program that will prompt for and read 2 words...

    Today you are to write a Java program that will prompt for and read 2 words of equal length entered by the user, and create a new word which contains the last letter of the 1st word, the last letter of the 2nd word, followed by the second to last character of the 1st word, followed by the second to last character of the 2nd word and so on. Be sure to use the same format and wording as in...

  • how do I write this code without the imports? I don't know what pickle is or...

    how do I write this code without the imports? I don't know what pickle is or os.path import pickle # to save and load history (as binary objects) import os.path #to check if file exists # character value mapping values = {'A': 1, 'B': 3, 'C': 3, 'D': 2, 'E': 1, 'F': 4, 'G': 2, 'H': 4, 'I': 1, 'J': 8, 'K': 5, 'L': 1, 'M': 3, 'N': 1, 'O': 1, 'P': 3, 'Q': 10, 'R': 1, ' S': 1,...

  • This is another attempt to ask this question: I need a Java program that asks the...

    This is another attempt to ask this question: I need a Java program that asks the user for a String. the string must be atleast 7 character and only words and/or numbers, the program should read this input and output “Valid”. No special characters or whitespaces are allowed, if so output “Invalid” *** Please note: The program must be able to know if the string is less than 7 characters and output INVALID. Also the program must be able to...

  • I need some help with Java. I need to write a Java program that generates a...

    I need some help with Java. I need to write a Java program that generates a set of random strings from a given string of same length where no character is ever repeated and character belong to the original string. See example. Example Input: “Hello World” (length 9) Output: “World oHlel” (length 9)

  • Note that the main function that I have provided does use <string.h> as it constructs test...

    Note that the main function that I have provided does use <string.h> as it constructs test strings to pass to your functions. However, your solutions for the 5 functions below may not use any of the built-in C string functions from the <string.h> library. Write a function called strcmp373. This function is passed two parameters, both of which are C strings. You should use array syntax when writing this function; that is, you may use [ ], but not *...

  • For this lab you will write a Java program that plays a simple Guess The Word...

    For this lab you will write a Java program that plays a simple Guess The Word game. The program will prompt the user to enter the name of a file containing a list of words. These words mustbe stored in an ArrayList, and the program will not know how many words are in the file before it starts putting them in the list. When all of the words have been read from the file, the program randomly chooses one word...

  • In java, write a program with a recursive method which asks the user for a text...

    In java, write a program with a recursive method which asks the user for a text file (verifying that the text file exists and is readable) and opens the file and for each word in the file determines if the word only contains characters and determines if the word is alpha opposite. Now what I mean by alpha opposite is that each letter is the word is opposite from the other letter in the alphabet. For example take the word...

  • CSC Hw Problems. Any help is appreciated I dont know where to start let alone what...

    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...

  • Java Question, I need a program that asks a user to input a string && then...

    Java Question, I need a program that asks a user to input a string && then asks the user to type in an index value(integer). You will use the charAt( ) method from the string class to find and output the character referenced by that index. Allow the user to repeat these actions by placing this in a loop until the user gives you an empty string. Now realize that If we call the charAt method with a bad value...

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