Access Millions of academic & study documents

A method String toGibberish() that returns a String containing the

Content type
User Generated
Showing Page:
1/5
A method String toGibberish() that returns a String
containing the \'gibberish\' version of the instance variable.
The rules for translating a word into gibberish are: If the
word begins with a consonant, follow the first letter with
\'itha\', and place a \'g\' before the rest of the original
word. So the word \'big\' would translate to \'bithagig\'. If
the word begins with a vowel, place \'itha\' at the front, and
put a \'g\' in front of the original word. So the word \'is\'
becomes \'ithagis\'. A method String reverse() that returns
a String that contains the characters of the instance
variable, but in reverse. A method int
numCharOccurrences(char ch) that returns a count of the
number of times the parameter char ch occurs in the
instance variable.
Solution
Gibberish.java
package org.students;
import java.util.Scanner;
public class Gibberish {
//Declaring static Variables
public static String str;
public static char[] temparray;
public static void main(String[] args) {

Sign up to view the full document!

lock_open Sign Up
Showing Page:
2/5
//Scanner object is used to get the inputs from the
user.
Scanner sc1=new Scanner(System.in);
//Calling a method.
String str1=toGibberish();
System.out.println(\"The Gibberish String
is:\"+str1+\"\ \");
//Calling a method.
String revstr=reverse();
System.out.print(\"Enter a Character :\");
char ch=sc1.next(\".\").charAt(0);
//Calling a method.
int nooftimes=numCharOccurrences(ch);
System.out.println(\"\ No of Times \'\"+ch+\"\' occurs
in the string:\"+nooftimes);
}
//Method which count the no of occurrences of a character
in char array
private static int numCharOccurrences(char ch) {
int count=0;
for(int i=0;i<temparray.length;i++)
{

Sign up to view the full document!

lock_open Sign Up
Showing Page:
3/5

Sign up to view the full document!

lock_open Sign Up
End of Preview - Want to read all 5 pages?
Access Now
Unformatted Attachment Preview
A method String toGibberish() that returns a String containing the \'gibberish\' version of the instance variable. The rules for translating a word into gibberish are: If the word begins with a consonant, follow the first letter with \'itha\', and place a \'g\' before the rest of the original word. So the word \'big\' would translate to \'bithagig\'. If the word begins with a vowel, place \'itha\' at the front, and put a \'g\' in front of the original word. So the word \'is\' becomes \'ithagis\'. A method String reverse() that returns a String that contains the characters of the instance variable, but in reverse. A method int numCharOccurrences(char ch) that returns a count of the number of times the parameter char ch occurs in the instance variable. Solution Gibberish.java package org.students; import java.util.Scanner; public class Gibberish { //Declaring static Variables public static String str; public static char[] temparray; public static void main(String[] args) { //Scanner object is used to get the inputs from the user. Scanner sc1=new Scanner(System.in); //Calling a method. String str1=toGibberish(); System.out.println(\"The Gibberish String is:\"+str1+\"\ \"); //Calling a method. String revstr=reverse(); System.out.print(\"Enter a Character :\"); char ch=sc1.next(\".\").charAt(0); //Calling a method. int nooftimes=numCharOccurrences(ch); System.out.println(\"\ No of Times \'\"+ch+\"\' occurs in the string:\"+nooftimes); } //Method which count the no of occurr ...
Purchase document to see full attachment
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.
Studypool
4.7
Indeed
4.5
Sitejabber
4.4