Question

In: Computer Science

in. java Write a program that reads a string from the user, and creates another string...

in. java

Write a program that reads a string from the user, and creates another string with the letters from in reversed order. You should do this using string concatenation and loops. Do not use any method from Java that does the work for you. The reverse string must be built. Do not just print the letters in reversed order. Instead, concatenate them in a string.

--- Sample run:
This program will create a string with letters in reversed order.
Enter a string: banana
The reversed string is: ananab
Bye

--- Sample run:
This program will create a string with letters in reversed order.
Enter a string: what the heck
The reversed string is: kceh eht tahw
Bye

Solutions

Expert Solution

//Java Program

import java.util.Scanner;

public class Reverse{
public static void main(String args[]){
String input;
Scanner in =new Scanner(System.in);
System.out.println("This program will create a string with letters in reversed order.");
System.out.print("Enter a string:");
input = in.nextLine();
  
System.out.println("The reversed string is:"+reverseString(input));
System.out.println("Bye");
in.close();
}
  
public static String reverseString(String str){
String newStr="";
for(int i=str.length()-1;i>=0;i--){
newStr+=str.charAt(i);
}
return newStr;
}
}
//sample output


Related Solutions

Write a Java program (name it PasswordTest) that reads from the user a string input (representing...
Write a Java program (name it PasswordTest) that reads from the user a string input (representing a password) and determines whether the password is “Valid Password” or “Invalid Password”. A valid password has at least 7 characters and includes at least one lower-case letter, at least one upper-case letter, at least one digit, and at least one character that is neither a letter nor a digit. Your program will need to check each character in the string in order to...
Write a program, Lab02_Q4.py, that inputs a string from the user, and creates a new string...
Write a program, Lab02_Q4.py, that inputs a string from the user, and creates a new string that deletes each non-alphanumeric character in the original string. You should solve this problem in 2 ways, first use a for loop that iterates through each character in the string, the second should use a while loop that iterates through a range. Keep spaces in the new string also. Hint: You can invoke the isalnum() function on a character, and it will return True...
Instructions: Create a Java program that reads a string entered by the user and then determines...
Instructions: Create a Java program that reads a string entered by the user and then determines and prints how many of each lowercase vowel (a, e, i, o, and u) appear in the entire string. Have a separate counter for each vowel. Also, count and print the number of non-vowel characters. Example: User enters: "This house is beautiful." a: 1 e: 2 i: 3 o: 1 u: 2 non-vowel:10
Write a JAVA program that reads in a string from standard input and determines the following:...
Write a JAVA program that reads in a string from standard input and determines the following: - How many vowels are in the string (FOR THE PURPOSE OF THIS PROGRAM 'Y' is NOT considered a vowel)? - How many upper case characters are in the string? - How many digits are in the string? - How many white space characters are in the string? - Modify the program to indicate which vowel occurs the most. In the case of a...
Using Java: Write a program that uses hash tables and reads in a string from the...
Using Java: Write a program that uses hash tables and reads in a string from the command line and a dictionary of words from standard input, and checks whether it is a "good" password. Here, assume "good" means that it (i) is at least 8 characters long, (ii) is not a word in the dictionary, (iii) is not a word in the dictionary followed by a digit 0-9 (e.g., hello5), (iv) is not two words separated by a digit (e.g.,...
Write a C++ or Java program that reads an input graph data from a user. Then,...
Write a C++ or Java program that reads an input graph data from a user. Then, it should present a path for the travelling salesman problem (TSP). In the assignment, you can assume that the maximum number ofvertices in the input graph is less than or equal to 20. Input format: This is a sample input from a user. 4 12 0 1 2 0 3 7 0 2 5 1 0 2 1 2 8 1 3 3 2...
Write a Java program that reads an input graph data from a user. Then, it should...
Write a Java program that reads an input graph data from a user. Then, it should present a path for the travelling salesman problem (TSP). In the assignment, you can assume that the maximum number of vertices in the input graph is less than or equal to 20. Input format: This is a sample input from a user. 4 12 0 1 2 0 3 7 0 2 5 1 0 2 1 2 8 1 3 3 2 0...
Java Write a program that reads 4 integer numbers from the user combine it into a...
Java Write a program that reads 4 integer numbers from the user combine it into a single number. You need to ask the user to first specify how to combine the numbers (forward or backward). Note that for the backward option you need to check that the last digits should be 0, also for the forward option you need to check that the fist digit is not 0. Use for loops and switch for the menu.                       4. Write an application...
Write Java program Lab52.java which reads in a line of text from the user. The text...
Write Java program Lab52.java which reads in a line of text from the user. The text should be passed into the method: public static String[] divideText(String input) The "divideText" method returns an array of 2 Strings, one with the even number characters in the original string and one with the odd number characters from the original string. The program should then print out the returned strings.
2. Write a Java program to read a string (a password)from the user and then   check...
2. Write a Java program to read a string (a password)from the user and then   check that the password conforms to the corporate password policy.   The policy is:   1) the password must be at least 8 characters   2) the password must contain at least two upper case letters   3) the password must contain at least one digit   4) the password cannot begin with a digit   Use a for loop to step through the string.   Output “Password OK” if the password...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT