Preview

6 String compare and PigLatin

Good Essays
Open Document
Open Document
464 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
6 String compare and PigLatin
Comparing Primitives vs
Comparing Strings
There is a difference

Comparing Primitives
• Primitives are compared with an operator:
== <
<=
>
>=
!=
//given an int called x, if( x == 100)…
//given a double called num, while(num >= 0)…
//given a boolean called done if(done == true)…

Comparing Strings
• String equality is compared with the dot-equals method: //given a String called word, if(word.equals(“Gamera01”) System.out.println(“Correct Password”); else System.out.println(“Incorrect Password”); if(! option.equals(“Y”) && !option.equals(“N”))
System.out.println(“that is not an option”);

Comparing Strings
• String order is compared with the dot-compareTo method: x.compareTo(y) returns a negative # if x < y returns a positive # if x > y returns zero if x.equals(y) if(word.compareTo(“MMM”) < 0)
System.out.println(word + “ is in the first ½ of the dictionary”); else System.out.println(word + “ is in the last ½ of the dictionary”);

• To better remember which way dot-compareTo is comparing, visualize the operator where the method call is: if(word.compareTo(“MMM”) < 0)

//if word < “MMM”

if(word.compareTo(“MMM”) > 0)

//if word > “MMM”

if(word.compareTo(“MMM”) == 0)

//if word ==“MMM”

Adding Strings together
• Concatination: add strings together using the
+ operator to return a new String.
String x = “hello”;
String y = “world domination”;
String z = x + “ “ + y.substring(0, 5);
System.out.println(z);

Adding Strings together
• Concatination: add strings together using the
+ operator to return a new String.
String x = “hello”;
String y = “world domination”;
String z = x + “ “ + y.substring(0, 5);
System.out.println(z);
//output: hello world

PigLatin Translator
• Input: a single word
• Output: the word in Piglatin.
• Rules:
– If the word starts with a vowel, add “way” to the end: toPig(“apple”) should return “appleway”
- If word starts with a consonant pair (“th”, “ch”, “st”, etc), move the pair to the end of the word and add “ay”: toPig(“shoe”) should return

You May Also Find These Documents Helpful

  • Satisfactory Essays

    Comma Splices

    • 505 Words
    • 3 Pages

    12. Today’s bankers owe more to their customers than they actually have in reserve; therefore they keep enough assets on hand to meet reasonable withdrawals.…

    • 505 Words
    • 3 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Pigs in Heavan

    • 638 Words
    • 3 Pages

    The book I will do my assignment on is Pigs in Heaven. Also the character I have chosen is Taylor Greer. Taylor Greer is a protagonist. Taylor Greer’s supporting character is Turtle who helps her make many decisions in life thorough the story. To fully understand Taylor Greer, it’s important to look at her many strengths and weaknesses. Her whole purpose is to make her daughter happy which will be noticed by her daughter later in the story.…

    • 638 Words
    • 3 Pages
    Satisfactory Essays
  • Good Essays

    CompareContrastEssay

    • 462 Words
    • 2 Pages

    Racism is a problem that the American people have grappled with since colonial times. Malcolm X and Michele Norris grew up in different environments. Michele Norris was raised in a comfortable middle-class family. On the other hand, Malcolm X came from an underprivileged home. He was a self-taught man who received little schooling and rose to greatness on his own intelligence and determination.…

    • 462 Words
    • 2 Pages
    Good Essays
  • Good Essays

    Comparison and Constrast

    • 1175 Words
    • 3 Pages

    Calvin Cordozar Broadus Jr. is one artist who had an incredible change in his career and his personal life. Cordozar best known as Snoop Dogg claims that he is Bob Marley reincarnated. After he visited Jamaica he said that this island changed his mind and his life, he had a spiritual and artistic awakening. The 41 years old rapper believe that peace and love are better than drugs and guns, is hard to believe that one of the greatest and famous rappers in the world would change from one day to other. The dog became a lion, those lyrics that used to talk about money and drug dealing now talk about peace, love and forgiveness, the gangsta rapper that everybody know had change to a Rastafarian.…

    • 1175 Words
    • 3 Pages
    Good Essays
  • Good Essays

    Compare Ans Contrast

    • 385 Words
    • 2 Pages

    The Orioles and Ravens are similar but yet not so similar after all. The two teams show comparison because both of the teams play in Maryland, there stadiums are right across the street from each other, they are both professional leagues , both have dye heart fans, has had there fare shares of wins and losses. The Orioles have been around in Maryland as there baseball team since 1954. The Orioles went to the World Championships in 1966, 1970, 1983. The Ravens have been around a little over then 13 years as Maryland’s football team but seem to have a bigger fan base then the Orioles. Also the Ravens have only one the super bowl once in 2000. Another similar trait that the Ravens and the Orioles have is that both of their mascot’s our birds.…

    • 385 Words
    • 2 Pages
    Good Essays
  • Good Essays

    Most people have never had to take care of a 300 pound pig before. Likewise, most people do not wake up every morning with a miniature pig in their bed. Farm pigs and miniature pigs are similar animals but the way they are fed, raised, and how big they get make them very different.…

    • 845 Words
    • 4 Pages
    Good Essays
  • Satisfactory Essays

    What comparisons can be found between the GCU Mission and Domains/CON Mission and Program Competencies (for your selected specialty track, links located in the Course Materials) with the AACN 's Essentials for Master 's Education for Advanced Practice Nursing (link located in the Week 1 Topic Materials)? Explain your rational.…

    • 410 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Compare Ad Contrast

    • 658 Words
    • 2 Pages

    Suspense movies are my favorite. “Yogisha X no Kenshin” was adapted into a film in South Korea and Japan, which was the best known novel of Japanese mystery novelists, Higashino Keigo. “Yogisha X no Kenshin” was translated to “The Devotion of Suspect” in English, formerly known as “Perfect Number”. The adapted film of Japanese version was different from the Korean version in characters settings, focused points, and endings.…

    • 658 Words
    • 2 Pages
    Satisfactory Essays
  • Better Essays

    Compare-Contrast

    • 1093 Words
    • 5 Pages

    This paper is on compare-contrast of two advertisements dealing with two beauty products. One will be targeted towards men, while the other will be targeted towards women. The two beauty products advertisements that will be compared and contrast are the Axe Body Spray advertisement (18-19) and the Victoria’s Secret fragrance mist advertisement (Bath and Body Works). Both advertisements use different marketing promotions technique to try to get the attention and win over their target audience. The manufacturers know in order to get the audience attention it has to rely on several demands of the audience; one of them is the sex appeal their products bring to the table, because that’s what evidently moves the product off the shelves. The manufacturers also try to impress the audience by using the passion, credibility, and the traditional demands that they need to sell their products. The Axe Body Spray advertisement is more effective than the Victoria’s Secret fragrance mist advertisement because of its emotions, authority, and cultural appeal.…

    • 1093 Words
    • 5 Pages
    Better Essays
  • Satisfactory Essays

    Compare and

    • 654 Words
    • 3 Pages

    In the movie, Pleasantville, and in the book, The Giver, there are many different similarities and differences. One similarity is that the communities are portrayed as utopias but in reality are actually dystopias. Another similarity is the weather and the fact that it’s extremely ideal. Also, in both the movie and in the book the communities have no understanding of sex or sexual feelings. However, in the book The Giver the people in the community are capable of these feelings, but they suppress them with a pill. On the other hand, in the movie there is no such thing as sexual feelings until Bud and Mary-Sue show up in Pleasantville and show the people what life is really all about. Some additional differences include: when Pleasantville’s weather changes and black and white change into color. Although there are many similarities of both communities the differences of both communities makes them both very different.…

    • 654 Words
    • 3 Pages
    Satisfactory Essays
  • Good Essays

    Argument Comparison

    • 446 Words
    • 2 Pages

    I believe the “Fighting Gun Violence” article is stronger than the NRA statement in the fact that “Fighting Gun Violence” article evenly uses its logos, pathos, and ethos throughout, unlike the NRA article where it relies on the pathos instead of giving actual solutions. The “Fighting Gun Violence” article is a response from Giffords and Kelly. This article covers the topic of gun violence in the USA and goes on to support their claim that changes in our laws need to take place to require responsible gun ownership and reduce gun violence. The second article from the NRA is a statement made by the National Rifle Association discussing their views on what congress should do with this gun violence dispute in America.…

    • 446 Words
    • 2 Pages
    Good Essays
  • Satisfactory Essays

    Compare and COntarst

    • 1518 Words
    • 5 Pages

    Egypt and Mesopotamia have both similarities and differences, throughout both of these civilizations from back to 3,500 B.C. The political and social structures in these civilizations were different and the same in their own way. The political differences between Egypt and Mesopotamia included hierarchy power, land control, and centralized government. The similarities between both civilizations are social class, male patriarchy, and kings.…

    • 1518 Words
    • 5 Pages
    Satisfactory Essays
  • Good Essays

    Conjoining and comparison

    • 1554 Words
    • 7 Pages

    Along with perception, memory and imagination name the main sensitive powers. Many of our memories are verbal and implement all the processes of thought, both perceptual and conceptual thought.…

    • 1554 Words
    • 7 Pages
    Good Essays
  • Good Essays

    Good morning/afternoon teachers and students. Racism was a major issue faced by many in the 20th Century. Feelings of isolation and being segregated as a result of being racially or ethnically different were common to many people at the time. Many poems and songs examine this issue of bigotry; two examples are Equality by Maya Angelou and the song Strange Fruit, recorded by the legendary jazz singer, Billie Holiday. Both of these songs examine this issue of racism, from different viewpoints.…

    • 867 Words
    • 4 Pages
    Good Essays
  • Good Essays

    Compare and Comtrast

    • 794 Words
    • 4 Pages

    Both Oedipus and Othello were virtuous and brave men that became the victims of two tragic downfalls. Oedipus and Othello are both tragic character. In the play Oedipus the king, Oedipus killed his father and married his mother and have children. However Othello ends up distrusting his wife, so he killed his wife. These two persons have similarities and differences in several characteristics that they are round characters, the vengeance that they experience upon themselves and upon their individual wives whether straight or circuitously, and their tragic.…

    • 794 Words
    • 4 Pages
    Good Essays

Related Topics