The project name of this exercise is ReverseWord The purpose of this assignment
ID: 3573611 • Letter: T
Question
The project name of this exercise is ReverseWord
The purpose of this assignment is to learn how to work with iteration and string processing. You get more practice on how to write all of your own code and Javadoc comments.
Problem Description
This problem is inspired by the book's Problem E6.9 on page 299.
You are going to write program that takes a word (or short phrase) from the command line (i.e. the input is in String args[]) and then will reverse the letters in the word.
Getting Started
There is no code to copy for the assignment. You get to do it all! Don't forget to provide proper Javadoc documentation.
We are going to do this exercise by writing the object that solves the problem by putting code into ReverseWord.java. Using the techniques shown on the web page titled [http://crowd.cs.sbcc.edu:7990/projects/CS105F2016/repos/allan.knight/browse/HowToStartEveryProject.md) to create a source file called ReverseWord.java. This is where your code will go.
Testing Your Code
Your ReverseWord.java should contain code for your solution to this problem. A sample run, assuming catalog is passed on the command line is shown below:
Once you've written your code run the code by single clicking on ReverseWord.java in the package explorer and selecting Run->Run from the menu or using the keyboard shortcut. Remember to update the run configuration so you can pass the word on the command line (See the MontyHallParadox assignment if you forget). Examine the output. Does it do what you want? If not, how can you modify the code to do what you want?
Explanation / Answer
The Objective of the program is to get a input string using String args[], and then give the output of reversing
the string.
Example I/p = catalog
O/p = golatac
Java code to reverse the string
import java.io.*;
import java.util.*;
public class reverseword{ // create a class reverseword
public static void main(String[] args){ // Array of strings to pass using String[] args
String input="";
System.out.println("Input the string"); // getting the input
try
{BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); // Reading text from character input stream
input = br.readLine(); // method to read the string
char[] try1 = input.toCharArray(); //converting string to char array
for (int i=try1.length-1;i>=0;i--)
System.out.print(try1[i]); // printing reverse string from array
}
catch (IOException e){ // catch if any exceptions
e.printStackTrace();}
}
}
Kindly save the code in the name of ReverseWord.java as prescribed in the question.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.