Question

In: Computer Science

Answer the following What is the difference between these two methods? Void display(int x) Int display(int...

Answer the following

  1. What is the difference between these two methods?

Void display(int x)

Int display(int s)

  1. Write a one line of code to generate random numbers from 35 to 55.( not a full program)

  1. Draw the UML diagram for a switch statement with 4 cases .

  1. Write a while loop to output the value of the variable x starting from 5, decreasing it by 0.5 each time, as long as x remains positive.
  1. Write a for loop to display the square of the first 25 odd positive integers
  1. Write a method called Test that takes one argument of type int and returns a bollean value. The method should return true if the integer is less than 100.Otherwise it should return False .

  1. For the above method in # 8 write a main method with declarations and method call statement which assigns the return value to a variable.

  1. Given method declaration statements before main

       Public static Double sum(double number);

Public static int sum(double y);

Is this a valid declaration? Why? _____________, _____________________

  1. What is wrong with the following code?

Public static Boolean result(int x)

{

If(x>0)

return 1;

}                                                                                                __________________________

  1. Assume the code below is part of a complete program, what will be the output of the code?
  1. for ( int count = 1; count < 100; count++);

cout << (10 * count) << “ “ ;

________________

  1. int total=75,score=20;         

total += score ;

system.println(“New Total is”);

system.printf(“%d,%n,%d%n%d”, ++ total, total − − ,total);                                                        

                                                                                         ____________

  1. int i = 1;

       while ( i <= 10)

        {

            if(i==8)

                        break;

               cout<< i+ 3;

             i++;

        }                                                                 ____________________

  1. int i,j;

        for(i=0;i<2;i++)

   {

          for(j=0;j<=3;j++)

                        {

                     cout<< “Hi”;

                        }

cout<<’*’;

        }                                                                           __________________________                                

Solutions

Expert Solution

Answer:

What is the difference between these two methods?

  1. Void display(int x) : It return nothing
  2. Int display(int s) : It return integer value

Write a one line of code to generate random numbers from 35 to 55.

int randInt = 35 + rand.nextInt(21);

Draw the UML diagram for a switch statement with 4 cases .

Write a while loop to output the value of the variable x starting from 5, decreasing it by 0.5 each time, as long as x remains positive.

double x = 5;

       while(x>0) {
           System.out.println(x);
           x -= 0.5;

       }

Write a for loop to display the square of the first 25 odd positive integers

int x = 1;

while(x<50) {

System.out.println(x*x);

x += 2;

}

Write a method called Test that takes one argument of type int and returns a bollean value. The method should return true if the integer is less than 100.Otherwise it should return False .

public static boolean Test(int x) {
       if ( x < 100 )
           return true;

       return false;
       }

For the above method in # 8 write a main method with declarations and method call statement which assigns the return value to a variable.

public static void main(String[] args) {
       boolean b = Test(10);
   }

Given method declaration statements before main

Public static Double sum(double number);

Public static int sum(double y);

Is this a valid declaration? Why?

No, This is not a valid declaration because "public" and "double" keyword should start with lower case.

What is wrong with the following code?

Public static Boolean result(int x)

{

If(x>0)

return 1;

}    

Keyword "public" and "boolean" should be lower case.

Assume the code below is part of a complete program, what will be the output of the code?

for ( int count = 1; count < 100; count++);

cout << (10 * count) << “ “ ;

Output : 10, 20, 30, ...... 980, 990

int total=75,score=20;         

total += score ;

system.println(“New Total is”);

system.printf(“%d,%n,%d%n%d”, ++ total, total − − ,total);                                                        

Output :

96

96

95

int i = 1;

       while ( i <= 10)

        {

            if(i==8)

                        break;

               cout<< i+ 3;

             i++;

        }

Output:

45678910

int i,j;

        for(i=0;i<2;i++)

   {

          for(j=0;j<=3;j++)

                        {

                     cout<< “Hi”;

                        }

cout<<’*’;

        }

Output :

HiHiHiHi*HiHiHiHi

Hope you like it

Any Query? Comment Down!

I have written for you, Please upvote the answer as it encourage us to serve you Best !


Related Solutions

What is the output of the following C program? #include<stdio.h> int fac (int x); void main(...
What is the output of the following C program? #include<stdio.h> int fac (int x); void main( ) {                         for (int i=1; i<=2; i++)                                     printf("%d", fac(i)); } int fac(int x) {                         x = (x>1) ? x + fac(x-1) : 100);                         return x; }
17.a. What is the difference between a void contract and a voidable contract? A) A void...
17.a. What is the difference between a void contract and a voidable contract? A) A void contract is an illegal contract that exists while a voidable contract has never existed but the parties can ask a court to set it aside. B) A void contract is a contract that never existed while a voidable contract exists but a court can set it aside to try to put the parties in their original position. C) A void contract is an illegal...
Given a program as shown below: #include <stdio.h> void function1(void); void function2 (int, double x); void...
Given a program as shown below: #include <stdio.h> void function1(void); void function2 (int, double x); void main (void) { int m; double y; m=15; y=308.24; printf ("The value of m in main is m=%d\n\n",m); function1(); function2(m,y); printf ("The value of m is main still m = %d\n",m); } void function1(void) { printf("function1 is a void function that does not receive\n\\r values from main.\n\n"); } void function2(int n, double x) { int k,m; double z; k=2*n+2; m=5*n+37; z=4.0*x-58.4; printf ("function2 is...
Given a program as shown below: #include <stdio.h> void function1(void); void function2 (int, double x); void...
Given a program as shown below: #include <stdio.h> void function1(void); void function2 (int, double x); void main (void) { int m; double y; m=15; y=308.24; printf ("The value of m in main is m=%d\n\n",m); function1(); function2(m,y); printf ("The value of m is main still m = %d\n",m); } void function1(void) { printf("function1 is a void function that does not receive\n\\r values from main.\n\n"); } void function2(int n, double x) { int k,m; double z; k=2*n+2; m=5*n+37; z=4.0*x-58.4; printf ("function2 is...
#include <stdio.h> #include <math.h> int fun(int); int main(void)    {     int i = 5, x...
#include <stdio.h> #include <math.h> int fun(int); int main(void)    {     int i = 5, x = 3;     i = fun(x);     printf("%d\n", i);     return 0; } int fun(int i) {      int res = 0;      res = pow (i , 3.0);      return ( res); }
What is the ouput of the following code? void loop(int num) { for(int i = 1;...
What is the ouput of the following code? void loop(int num) { for(int i = 1; i < num; ++i) { for(int j = 0; j < 5; ++j) { cout << j; } } } int main() { loop(3); return 0; }
Answer the following questions: What is the difference between two samples that are dependent and two...
Answer the following questions: What is the difference between two samples that are dependent and two samples that are independent? Give an example of each. Explain how to perform a two-sample z-test for the difference between the means of two populations using large independent samples. What conditions are necessary in order to use the z-test to test the difference between two population means?
#include<iostream> using namespace std; class point{ private: int x; int y; public: void print()const; void setf(int,...
#include<iostream> using namespace std; class point{ private: int x; int y; public: void print()const; void setf(int, int); }; class line{ private: point ps; point pe; public: void print()const; void setf(int, int, int, int); }; class rectangle{ private: line length[2]; line breadth[2]; public: void print()const; void setf(int, int, int, int, int, int, int, int); }; int main(){ rectangle r1; r1.setf(3,4,5,6, 7, 8, 9, 10); r1.print(); system("pause"); return 0; } a. Write function implementation of rectangle, line and point. b. What is...
What is time Complexity each of the following function? 1- void function(int n) {             for (int...
What is time Complexity each of the following function? 1- void function(int n) {             for (int i=n/2; i<=n; i++)                           for (int j=1; j<=n/2; j++)                                     for (int k=1; k<=n; k = k * 2)                                                 print ”Hello”; } 2- void function(int n) {             for (int i=n/2; i<=n; i++)                           for (int j=1; j<=n; j = 2 * j)                                     for (int k=1; k<=n; k = k * 2)                                                 print ”Hello”; } 3- void function(int n) {             for (int i=1; i<=n; i++)                           for (int j=1;...
What are the methods for calculating the free energy difference between two states? What are the...
What are the methods for calculating the free energy difference between two states? What are the roles of MD/MC simulations for calculating the free energy? Name one of the enhanced sampling methods that utilize the Metropolis algorithm.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT