Write a program that prompts the user enter a word, and determines the first half and...

80.2K

Verified Solution

Question

Programming

  1. Write a program that prompts the user enter a word, anddetermines the first half and second half of the word. Print thefirst and second half of the word on different lines. Sample runsof the program are shown below. Note: If the word is an odd numberof letters, the first half should contain fewer letters (as shownin sample run #2)

SAMPLE PROGRAM RUN#1                    

Enter a word: carrot

First half: car

Second half: rot

SAMPLE PROGRAM RUN#2                            

Enter a word: plant

First half: pl

Second half: ant

Complete your answer by typing code below

import java.util.Scanner;

public class WordHalves

{

public static void main(String[] args)

{

Scanner reader = new Scanner(System.in);

System.out.print(\"Enter a word: \");

String word = reader.nextLine();

}

}

Answer & Explanation Solved by verified expert
4.2 Ratings (591 Votes)
OUTPUT import javautilScannerpublic class Main public static void mainString args Scanner    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students