Write a program that prompts the user for a String value and a character value. The program should then find the last occurrence of the provided character in the provided String and display the corresponding index. If the character is not found in the String, display -1. For additional challenge, create a multi-class solution. The business class should consist of two instance varaibles to store the user provided values and one method to accomplish the given task. The tester class should call the instance method to test the behavior.
import java.util.Scanner; //reads data from input stream
class CharacterChecker
{
//instance variables
String original;
char data;
//parameterized constructor
CharacterChecker(String original,char data)
{
this.original=original;
this.data=data;
}
int findLastOccurence()
{
int found=-1;
for(int i=original.length()-1;i>=0;i--)
{
if(original.charAt(i)==data)
{
found=i;
break;
}
}
return found;
}
}
class Tester
{
public static void main(String[] args)
{
Scanner input=new Scanner(System.in);
System.out.println("Enter String:");
String original=input.nextLine();
System.out.print("Enter character to search in string: ");
char data=input.next().charAt(0);
CharacterChecker checker=new CharacterChecker(original,data);
int found=checker.findLastOccurence();
if(found!=-1)
System.out.println("The given "+data+" is found at "+found+" in
"+original);
else
System.out.println("The given "+data+" is not found in
"+original);
}
}
Output
koushikhp@koushikhpnew:~$ java Tester
Enter String:
Welcome
Enter character to search in string: e
The given e is found at 6 in Welcome
koushikhp@koushikhpnew:~$ java Tester
Enter String:
Hai welcome to Computers
Enter character to search in string: o
The given o is found at 16 in Hai welcome to Computers
koushikhp@koushikhpnew:~$ java Tester
Enter String:
Hai welcome
Enter character to search in string: a
The given a is found at 1 in Hai welcome
koushikhp@koushikhpnew:~$ java Tester
Enter String:
HAI WELCOME
Enter character to search in string: B
The given B is not found in HAI WELCOME
Write a program that prompts the user for a String value and a character value. The...
Write a C program that prompts the user to enter a binary value, multiplies it by ten, then displays the result in binary. (“Binary” here means that the user communicates with the program in ones and zeros.) Your main function should a) declare a char array, b) call the readLn function to read from the keyboard c) call a function to convert the input text string to an int d) multiply the int by ten e) call a function to...
1. Backward String Design a program that prompts the user to enter a string and then displays the string contents backward. For instance, if the user enters “gravity” the program should display “ytivar" -VB or Visual Studio. It must be turned into a GUI program. Make sure to write comments and include pseudocode. -Paste a screenshot of the pseudocode, the VB code, and of the program running into a PDF.
Write a program that prompts the user to enter a question
(string) and display whether the
question is correct. It is correct if it ends with the
question mark (?)
----vyrovusmyzustning%20Class.pdf Programs with String Class Write a program that prompts the user to enter a question (string) and display whether the question is correct. It is correct if it ends with the question mark (?) Ask a question? Ask a question? How old are you What is your name? That's...
(Process a string) Write a program that prompts the user to enter a string and displays its length and its first character. java StringLength Enter a string:Does quantum determinacy have anything to with whether human cognition is deterministic? The string is of length 88 and the first character is D import java.util.Scanner; class StringLength{ public static void main (String args[]){ Scanner input = new Scanner(System.in); System.out.println("Enter a string:"); String ans = input.nextLine(); System.out.println("The string...
Complete the following program so it prompts the user for 3 integers and displays the smallest of the 3 numbers. For instance, if the user provided 7 4 and 12, then the program would display 4. import java.util.Scanner; public class Program3{ public static void main(String[] args) { Scanner kb = new Scanner(System.in);
Write a program that prompts a user for an input string of length at least two and prints the string with the first half in upper case and the second half in lower case. If the length of the string is odd, the "second half" should be one character longer than the "first half". Show Hint
NO LOOPS, write a program, in Java, that prompts the user for a hexadecimal string of EXACTLY 4 hex digits, no more, no less, converts the hexadecimal value to its decimal value using string, character parsing, and Math methods learned in this chapter, and then prints the original string and its converted decimal value. NOTE: Hex digits may be in UPPER or lower case.
Write a program that prompts the user for a string and stores the user's string into a variable using getline(). After receiving the string, the program counts and displays the number of vowels in the string. Then, the program should prompt the user if they would like to enter another string.
Design a program that prompts the user to enter a string, and displays the character that appears most frequently in the string. (Please read the problem above carefully. I'm asking this question for the second time because the last answer I received wasn't even paying attention to what the question asked for.) Answer MUST be using Flowgorithm with screenshots. Please attach a screenshot of the program successfully running in flowgorithm as well to confirm proper output. Thanks for understanding!
In Java, write a program that prompts the user to input a sequence of characters and outputs the number of vowels. You will need to write a method to return a value called isAVowel which will return true if a given character is a vowel and returns false if the character is not a vowel. A second method, called isAConstant, should return true if a given character is a constant and return false if the character is not a constant....