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,...
Very easy: Write an EBNF rule that describes the following for statement in Java for (...
Very easy: Write an EBNF rule that describes the following for statement in Java for ( counter = 1; counter <= 10; counter ++) { sum=sum+1; } Then test your EBNF rule in Java as a recursive-descent subprogram
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...
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 schema: Suppliers(sid: integer, sname: string, address: string) Parts(pid: integer, pname: string, color: string)...
Consider the following schema: Suppliers(sid: integer, sname: string, address: string) Parts(pid: integer, pname: string, color: string) Catalog(sid: integer, pid: integer, cost: real) The key fields are underlined, and the domain of each field is listed after the field name. Therefore sid is the key for Suppliers, pid is the key for Parts, and sid and pid together form the key for Catalog. The Catalog relation lists the prices charged for parts by Suppliers. WRITE THE FOLLOWING QUERIES IN RELATIONAL ALGEBRA...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT