This is for java code; any help would be greatly appreciated and if you could pl
ID: 3667996 • Letter: T
Question
This is for java code; any help would be greatly appreciated and if you could please add comments if you have code I would be thankful for that as well.
Write a java application that will do the following:
Prompt for and input a string from the user (String may contain spaces)
Print the length of the String.
Print the first word of the String
Prin the String in all uppercase
print the string in all lowercase
print the string with all of the 'e' characters changed to 'a'
print the location of the first 't' in the String
print the last character of the String
if the string is longer than 8 character, print the first 8 characters of the String. Otherwise, print the entire String.
Once again thank you in advanced for your help.
Explanation / Answer
import java.io.*;
import java.util.Scanner;
public class StringVariables {
public static void main (String[] args){
Scanner user_input = new Scanner( System.in );
String input_string;
System.out.print("Enter your first name: ");
input_string = user_input.nextLine( );
System.out.print("length of string: ");
System.out.println(input_string.length());
System.out.println(input_string.split(" ")[0]);
System.out.println(input_string.toUpperCase());
System.out.println(input_string.toLowerCase());
System.out.println(input_string.replace('e', 'a'));
System.out.println(input_string.indexOf( 't' ));
if (input_string.length() > 8) {
else {
System.out.println(input_string);
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.