Question

In: Computer Science

Note: The answers to the following questions should be typed in the block of comments in...

Note: The answers to the following questions should be typed in the block of comments in the Assignemnt2.java file. Please make sure they're commented out (green). Type them neatly and make them easy to read for the graders.

Given the String object called myString with the value "Practice makes perfect!" answer the following questions.

Question #1 (1pt): Write a statement that will output (System.out) the number of characters in the string.
Question #2 (1pt): Write a statement that output the index of the character ‘m’.
Question #3 (1 pt): Write a statement that outputs the sentence in uppercase letters

Question #4 (1 pt): Write a statement that uses the original string to extract the new string "perfect" and prints it to the screen
Question # 5 (2 pts): What do the following expressions evaluate to in Java given int x = 3, y = 6;

a) x==y/2
b) x%2==0||y%2!=0 c) x–y<0&&!(x>=y) d) x+6!=y||x/y<=0

Question # 6 (1 pt): What does the following statement sequence print? (page 63)

String str = “Harry”;
int n = str.length();
String mystery = str.substring(0,1) + str.substring(n-1, n);
System.out.println(mystery);

Solutions

Expert Solution

1) & 2) & 3) & 4) & 5)

// Screenshot of the code & output

// code to copy

Assignemnt2.java

public class Assignemnt2 {

   public static void main(String[] args) {
   String myString = "Practice makes perfect!";
     
//Q1 - the number of characters in the string
System.out.println(myString.length( ));

// Q2 - the index of the character 'm'
System.out.println(myString.indexOf('m'));

// Q3 - the sentence in uppercase letters
System.out.println(myString.toUpperCase());
  
// Q4 - extract the new string "perfect"
System.out.println(myString.subSequence(0,8));

   }

}

5)

// Screenshot of the code & output

// code to copy

Main.java


public class Assignemnt2 {

   public static void main(String[] args) {
       int x = 3, y = 6;
      
       // a statement
       System.out.println(x==y/2);
      
       // b statement
       System.out.println(x%2==0||y%2!=0);
         
       // c statement
       System.out.println(x-y<0&&!(x>=y));
         
   // d statement
       System.out.println(x+6!=y||x/y<=0);

   }

}

6)

// Screenshot of the code & output

// code to copy

Main.java

public class Assignemnt2 {

   public static void main(String[] args)
   {      
       String str = "Harry";
       int n = str.length();
       String mystery = str.substring(0,1) + str.substring(n-1, n);
       System.out.println(mystery);
   }

}


Related Solutions

Please choose three questions from the following options. This should be in essay form and typed....
Please choose three questions from the following options. This should be in essay form and typed. Double spaced. 12-point font. Utilize the MLA Format when citing your work. Answer the following questions completely. Define the terms and theories and make the necessary connections to the real world. I am looking for real life and professional connections. These answers must be well thought out and substantiated. Make sure that you underline the term that you are defining and give a thorough...
1. Please give concise and precise answers for the following questions. Your answers should be no...
1. Please give concise and precise answers for the following questions. Your answers should be no more than five (5) sentences. a) What is consolidation (5 points)? b) Is consolidation the only reason why soil layers having settlements (5 points)? c) Under what kind(s) of condition will soil layers consolidate (5 points)? d) What are the basic assumptions of Terzaghi’s consolidation theory (5 points)? e) Based on the consolidation theory proposed by Karl Terzaghi, which factor from the results of...
Understand the code and explain the code and answer the questions. Type your answers as comments....
Understand the code and explain the code and answer the questions. Type your answers as comments. #include #include using namespace std; // what is Color_Size and why it is at the end? enum Color {        Red, Yellow, Green, Color_Size }; // what is Node *next and why it is there? struct Node {        Color color;        Node *next; }; // explain the code below void addNode(Node* &first, Node* &last, const Color &c) {        if (first == NULL)...
1- First question Externalities Homework Answer the following questions. All answers must be typed. Suppose coal...
1- First question Externalities Homework Answer the following questions. All answers must be typed. Suppose coal burning firms are emitting excessive pollution into the air. Suggest two ways the government can deal with this market failure. If I neglect or refuse to cut the grass on my front lawn, what are the externalities involved? Suggest two ways the government might deal with this issue. Why does the government subsidize the purchase of college educations, but not the purchase of hamburgers?...
Answer the following questions. Your answers should address all parts of the questions and be approximately...
Answer the following questions. Your answers should address all parts of the questions and be approximately 300-400 words each. Make sure to thoroughly support all answers with accurate details and relevant evidence from the textbook and other resources. 1. Several coworkers are in the lunchroom on their lunch break. Sam and his friend George are having a rather loud conversation about the party they attended over the past weekend. George relates a joke that he heard at the party; it...
Answer the following questions. Each answer should not exceed one typed page. Q1. A. Do you...
Answer the following questions. Each answer should not exceed one typed page. Q1. A. Do you think performance appraisals should be done? Do you think forced ranking is a good performance management system? Why or why not? Q2. ​How important is it that the effectiveness of a training program be measured in dollar terms? Why is it important to measure training effectiveness in the first place?
Answer the following questions. Each answer should not exceed one typed page. Q3. It has been...
Answer the following questions. Each answer should not exceed one typed page. Q3. It has been argued that training can lead to turnover, but career development can reduce it. Differentiate between training and career development. Why might training lead to turnover while career development might improve retention? Explain. Q4. According to a 2010 study by economists Angus Deaton and Nobel Prize–winning psychologist Daniel Kahnerman, “high income doesn’t bring you happiness…[T]he further a person’s household income falls below $75,000, the unhappier...
Should go to the following link and post their comments.
  Should go to the following link and post their comments. https://www.khanacademy.org/economics-finance-domain/macroeconomics/income-and-expenditure-topic/is-lm-model-tutorial/v/loanable-funds-interpretation-of-is-curve
Please I need clear and typed answers to these two questions: Q1)Explain the two types of...
Please I need clear and typed answers to these two questions: Q1)Explain the two types of file compression? Then determine the best compression strategy suited for: a- Photograph of sailboat on ocean. b- Journal article explaining nanotechnology. Q2)What are the advantages and disadvantages of Description-Based Encoding and Command-Based Encoding?
Short essay questions. Typed answers, please 6) Why and how did the South and the West...
Short essay questions. Typed answers, please 6) Why and how did the South and the West of the U.S. catch up with the Northeast in terms of population, economic growth, and industrial output? 7) How does California differ from the other states? 8)  Why has Quebec sought separation from the Canadian federation? 9) How does Canada differ from the United States? 10) What is NAFTA? What have been the benefits of NAFTA to its members?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT