Answer:
The solution code is as below:
- Scanner input = new Scanner(System.in);
- System.out.print("Input a string: ");
- String inStr = input.nextLine();
- int strLen = inStr.length();
-
- while(inStr.equals("Quit") != true && inStr.equals("quit") !=true && inStr.equals("q") != true){
-
- for(int i= 0; i < strLen; i++){
- System.out.print(inStr.charAt(strLen - 1 - i));
- }
-
- System.out.println();
- System.out.print("Input a string: ");
- inStr = input.nextLine();
- strLen = inStr.length();
Explanation:
Firstly, we create a Scanner object,<em> input</em> (Line 1).
Next, we use the Scanner object nextLine() method to get a text input from user (Line 3).
We create a while loop and set the condition so long as the input text is not equal to "Quit", "quit" or "q" (Line 6), the program should proceed to print the input text in reverse (Line 8-10). To print the text in reverse, we can apply the expression<em> length of string - 1 - current index</em>. This will ensure the individual letter is read from the last and print the text in reverse.
Next, prompt the user to input a new text (Line 13-14) and repeat the same process of printing text in reverse so long as the current input text is not "Quit", "quit" or "q".
Answer:
Cheese c =new Velveeta( );
Food f =new Velveeta( );
Food f =new Cheese( );
Explanation:
The super-class is the parent class from which features and attributes are inherited from while the subclass or the child class is the class inheriting from the super or parent class.
In Java, the object instance of a class is created with the syntax;
class_name instance_name = new class_name();
Food is the super or parent class of Cheese (which makes Cheese its subclass) and Cheese is the parent class of Velveeta. The extends keyword is used to denote inheritance.
Answer:
push, pop, top, clear
Explanation:
push: add a new value
pop: remove and return top value
top: return top value without removing
clear: remove all values