Question

In: Computer Science

Q1# Consider the following string: String hello = "Hi girls! hope your assignment1 is very easy.";...

Q1# Consider the following string:
String hello = "Hi girls! hope your assignment1 is very easy.";
a. What is the value displayed by the expression hello.length()?
b. What is the value returned by the method call hello.charAt(12)?
c. Write an expression that refers to the letter p in the string referred to by hello


Q2# Modify the program to use a "while-do" loop instead of "for" loop.


int sum = 0;
int number = lowerbound; // declare and init loop index variable
while (number <= upperbound) { // test
sum += number;
++number; // update
}

Solutions

Expert Solution

1.

a)

String length is :45 that means there are 45 charecters in the string

b)

charecter at 12 index position is "p"

c)

Index of the letter p is 12

hello.indexOf("p");

This is the expresion which used to find the charecter at 12 th index position

2.

Using for loop

int sum = 0;

for( int number=lowerbound;number<=upperbound;number++)
       {
           sum+=number;
       }

using do while loop

int sum = 0;
       int number =lowerbound; // declare and init loop index variable
       do
       {
           if(number <= upperbound)
           {
               sum += number;
               ++number;
           }
          
       }
       while(number <= upperbound);
   }


Related Solutions

[after §3.22 − easy] String Processing : Consider the following code fragment: 1 int a =...
[after §3.22 − easy] String Processing : Consider the following code fragment: 1 int a = 20; 2 int b; 3 double x = 3.5; 4 String s = "All"; 5 char ch; 6 7 x += a; 8 x--; 9 a /= 4 - 1; 10 b = s.length(); 11 b += 4; 12 s += "is well"; 13 ch = s.charAt(b); 14 System.out.println("a = " + a + ", b = " + b); 15 System.out.println("x = "...
Hi,This question is very important and I need a quick your answer.Br//Ha a. Consider an economy...
Hi,This question is very important and I need a quick your answer.Br//Ha a. Consider an economy that is characterised by the following Phillips curve: ? = ?- − ?(? − ?e ), where ? is unemployment, ?- is the natural rate of unemployment, ? is inflation, ?e is inflation expectations and ? > 0 is a parameter. Suppose that the loss function of the central bank is given by: ?(?, ?) = ? + 3/2 ?2, Agents are assumed to...
Hi,This question is very important and I need a quick your answer.Br//Ha a. Consider an economy...
Hi,This question is very important and I need a quick your answer.Br//Ha a. Consider an economy that is characterised by the following Phillips curve: ? = ?- − ?(? − ?e ), where ? is unemployment, ?- is the natural rate of unemployment, ? is inflation, ?e is inflation expectations and ? > 0 is a parameter. Suppose that the loss function of the central bank is given by: ?(?, ?) = ? + 3/2?2, Agents are assumed to be...
Hi, the following is the question that I have been facing now and I really hope...
Hi, the following is the question that I have been facing now and I really hope if someone can help me with that. Problem analysis: This section is your analysis of the issues surrounding greenhouse gases and a carbon tax. You need spell out what the main problems of issues are facing Canadians. Use specific references when making your arguements. If more than one solution exists, then make an argument for focusing on just that one solution. In addition, how...
Hi, the following is the question that I have been facing now and I really hope...
Hi, the following is the question that I have been facing now and I really hope somebody can help me with it.    Problem analysis: This section is your analysis of the issues surrounding greenhouse gases and a carbon tax. You need to spell out what are the main problems or issues facing Canadians. Use specific references when making your arguments. If more than one solution exists, then make an argument for focusing on just that one solution. In addition,...
Please explain each step very carefully and make sure your handwriting is easy to read. Thank...
Please explain each step very carefully and make sure your handwriting is easy to read. Thank you Question: Suppose p(x) is a polynomial of degree n with coefficients in R and suppose p(x) has exactly n real roots. Show that p'(x) has exactly n-1 real roots.
Consider the following information for Hope Co.: State            Probability X          Y Boom       &
Consider the following information for Hope Co.: State            Probability X          Y Boom          .35              15%   10% Normal        .50              10%   8% Recession .15                5%       10% Compute using 2 different ways the expected return for a portfolio with an investment of $8,000 in asset X and $2,000 in asset Y. Based on your previous answer, what is the standard deviation for the same portfolio. If the expected inflation rate is 4.5% and the nominal expected return of the previous portfolio is the one computed in question Q1), what are...
Question (3) Consider the following relations: Student(snum: integer, sname: string, major: string, level: string, age: integer)...
Question (3) Consider the following relations: Student(snum: integer, sname: string, major: string, level: string, age: integer) Class(name: string, meets at: string, room: string, fid: integer) Enrolled(snum: integer, cname: string) Faculty(fid: integer, fname: string, deptid: integer) The meaning of these relations is straightforward; for example, Enrolled has one record per student-class pair such that the student is enrolled in the class. Write the following queries in Oracle SQL. No duplicates should be printed in any of the answers. i) (2 points)...
Hi Archie. You made a very interesting observation in your posting regarding restatement issues with specific...
Hi Archie. You made a very interesting observation in your posting regarding restatement issues with specific statements. It might be interesting to explore this a little bit more. We typically think of the income statement when we hear of a financial restatement, but it’s certainly possible for other statements to be impacted. Let’s examine the statement of cash flows. We know that the change in cash during the period should reconcile with the change that we see in cash between...
Consider the following description for a university database system, split into numbered sentences for easy reading:
Consider the following description for a university database system, split into numbered sentences for easy reading:(i) The university offers several modules, and students can enroll into one or more modules.(ii) Each module, identified using a unique ID, will involve multiple assignments.(iii) Each assignment will be allocated a number that is unique within that module (but not necessarily across modules).Which entity among those in the description is suitable to be modeled as a WEAK ENTITY SET?A. AssignmentB. ModuleC. StudentsD. University
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT