Ask your own question, for FREE!
Computer Science 19 Online
yujoz:

Create a Java application that prompts the user for a word and then outputs the following information about the word they enter: The number of characters in the word. The substring from the 4th character to the 6th character (inclusive). The substring from character 2 to the end of the word. The location of the first ‘a’ in the word. The location of the last ‘a’ in the word. The character at spot (or index) 4 of the word.

yujoz:

sample output, programming language is java

Vocaloid:

@SmokeyBrown

SmokeyBrown:

Hello, and welcome to QuestionCove! For this program, there are certain tasks you will need to complete. I will try to list some methods and strategies you might consider in order to complete those tasks. To take input from the user, you can use a Scanner object. To count the number of characters in a String, you can use the .length() method, which is built into the String class. To find a substring of a string based on the character index, you can use the .substring() method, which is built into the String class. To find the characters at an index in a string you can sue the .charAt() method, which is built into the String class. To find the location of the first and last 'a' character, you can iterate through the String character by character (perhaps using a loop of some sort) with a condition to check whether the current character is 'a' as well as to keep track of the index of the current character. You can go through the String starting from the beginning or the end, depending on whether you want to find the first or last 'a'. I hope this helps! Tomorrow, if you'd like more guidance or have questions, please feel free to reach out to me more. I'm looking forward to helping you figure this out :)

SmokeyBrown:

It might also be a good idea to code in responses for certain "edge cases" or exceptions where the program might not perform as expected. For example, what if the String does not have a 4th character? What if there are no "a"s in the String, etc? Of course, we can think about that more once we've got the basic structure of the program and some of the coding done.

yujoz:

Okay thank you so much for your help! my friend @xjezzer told me about this site and wow it is amazing! Thank you so much. Ill get back to you if I need any help

SmokeyBrown:

I'm glad you found it helpful! If you need more help, I can certainly try to see what I can do

yujoz:

Hi, I've been out of town and I have just come back. Could you help me with the general idea with the code and help me out because with all the other problems I have had to do, this one is by far much harder and I don't really undestand

yujoz:

maybe with a replit

SmokeyBrown:

Yeah, sure I don't mind, I'll see if I can put together some code to help explain some of the things you'd need for this assignment. And I'll put that here https://replit.com/join/hmhzwpgywy-hgu999

SmokeyBrown:

Well, yujoz, I pretty much ended up writing the code for you. I went back and replaced some of the key methods with "________" blank space, that I'll let you fill in yourself as an exercise. This means you will NOT be able to simply copy/paste the code and will also let me feel as though I did not do all of your work for you. I made sure to test the code, so if you can fill in the blanks with the appropriate methods, it should work fine Please let me know if you need any more help or have any more questions, and I'll try to be around for support

yujoz:

Okay I cannot express how thankful I am. This whole site as a whole is amazing. Thank you so much

SmokeyBrown:

You're very welcome! I'm glad you're finding the site to be helpful :)

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Latest Questions
euphoriiic: I drew more people !! ud83eudd17.
1 hour ago 40 Replies 3 Medals
euphoriiic: I drew markk ud83eudd17.
3 hours ago 34 Replies 2 Medals
LOLIAteYourMom: u2212243 = u22129(10 + x)
6 hours ago 0 Replies 0 Medals
Bubblezz: Art for @jeromeccv
6 hours ago 13 Replies 3 Medals
Bubblezz: Art for @jeromecv
10 hours ago 0 Replies 0 Medals
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!