Question

In: Computer Science

projectOne (Please be sure to include screenshots of the test runs for all programs) A. write...

projectOne (Please be sure to include screenshots of the test runs for all programs)

A.

write a program the computes nx and store the result into y

You can use y = Math.pow( Mantissa, exponent)

Requirements:
Besides main() your program must have one method with two parameters, one double and one int

n and x are positive numbers read from the keyboard
if the user makes an entry that does not meet this criteria, the user must be given to opportunity retry the entry

the user must be able to quit prior to entering values for n and x

Your method must compute y and return the result to its caller; the caller will print the result

After printing the result, the user must be queried again if there are other values to compute; if the answer is no exit the program, but if the user replies yes, then repeat the computation

B.
Write a Java program that takes an integer array parameter and returns the sum of integers contained within the array.

C.
Correct code to output the folowing:
0 2 4 6 8 10 12 14 16 18

int[] numbers = new int[10];

for(int i=0; i < numbers.length; ++i)

        numbers[i] = i * 2;

for(int i=0; i < numbers.length; i++)

        System.out.print(numbers[++i] + " ");

System.out.println();

D.

Correct the code to prints the following:

0 1 2 3 4 5 6 7 8 9

int[] numbers = new int[10];

for(int i=0; i < numbers.length; ++i)

        numbers[i] = i * 3;

for(int i=0; i < numbers.length; ++i)

        System.out.print(numbers[i] / 2 + 1 + " ");

System.out.println();

Solutions

Expert Solution

  1. The first part can be done as follows :
    import java.util.*;
    import java.lang.*;
    import java.io.*;
    
    /* Name of the class has to be "Main" only if the class is public. */
    class power
    {
            public static void main (String[] args) throws java.lang.Exception
            {
                    Scanner sc= new Scanner(System.in);      
                    System.out.print("Enter the mantissa : ");  
                    int n = sc.nextInt();  
                    
                    System.out.print("\nEnter the exponent : ");  
                    int x = sc.nextInt(); 
                    
                    System.out.print("\nn^x is : " + Math.pow(n, x));
            }
    }
  2. Code for part B

    /* package whatever; // don't place package name! */
    
    import java.util.*;
    import java.lang.*;
    import java.io.*;
    
    /* Name of the class has to be "Main" only if the class is public. */
    class sumArray
    {
            public static void main (String[] args) throws java.lang.Exception
            {
                    Scanner sc= new Scanner(System.in);      
                    System.out.print("Enter the size of array : ");  
                    int n = sc.nextInt();  
                    
                    int arr[] = new int[n];
                    int sum  = 0;
                    
                    for(int i = 0; i<n; i++)
                    {
                            System.out.print("\nEnter element #" + (i+1) + " : ");
                            int x = sc.nextInt();
                            arr[i] = x;
                            sum = sum + arr[i];
                    }
                    
                    System.out.print("\nThe sum of all the elements is : " + sum);
                    
            }
    }
  3. The code for part C should be corrected as follows: Change the ++i in the print statement to i.
    int[] numbers = new int[10];
    
                    for(int i=0; i < numbers.length; ++i)
                    numbers[i] = i * 2;
    
                    for(int i=0; i < numbers.length; i++)
    
            System.out.print(numbers[i] + " ");
    
    System.out.println();
  4. The code for part D should be corrected as follows: Change numbers[i]/2 + 1 to numbers[i]/3
    int[] numbers = new int[10];
    
    for(int i=0; i < numbers.length; ++i)
    
            numbers[i] = i * 3;
    
    for(int i=0; i < numbers.length; ++i)
    
            System.out.print((numbers[i] / 3)  + " ");
    
    System.out.println();

Please upvote the answer if you find it helpful.


Related Solutions

) Write queries for the following. Include screenshots of the queries and the outputs. Create a...
) Write queries for the following. Include screenshots of the queries and the outputs. Create a procedure named DisplayInfo which takes customer name as a parameter and displays information of that customer. (database – sql_store)
Please comments this C++ code and show screenshots of the outputs main.cpp #include<iostream> #include<vector> #include<string> #include"BST.h"...
Please comments this C++ code and show screenshots of the outputs main.cpp #include<iostream> #include<vector> #include<string> #include"BST.h" #include"BST.cpp" using namespace std; std::vector<std::string> tokenize(char line[]) {    std::vector<std::string> tok;        std::string word = "";        for (int i = 0; i < strlen(line); i++)        {            if (i == strlen(line) - 1)            {                word += line[i];                tok.push_back(word);                return tok;       ...
For this, problem, please include the excel procedure you used to arrive at an answer (screenshots,...
For this, problem, please include the excel procedure you used to arrive at an answer (screenshots, explanation, actual file, etc.). Brokerage Overall Satisfaction with Electronic Trades Satisfaction with Trade Price Satisfaction with Speed of Execution Scottrade, Inc. 3.5 3.4 3.4 Charles Schwab 3.4 3.2 3.3 Fidelity Brokerage Services 3.9 3.1 3.4 TD Ameritrade 3.7 2.9 3.6 E*Trade Financial 2.9 2.9 3.2 (Not listed) 2.7 2.5 3.2 Vanguard Brokerage Services 2.8 2.6 3.8 USAA Brokerage Services 3.6 2.4 3.8 Thinkorswim 2.6...
Please write a discharge plan for the following patient. Make sure to Include: -Explanation of diagnosis...
Please write a discharge plan for the following patient. Make sure to Include: -Explanation of diagnosis -Follow-up plans after discharge -Resources for questions, concerns or needs (i.e. Home health, physical therapy, counseling etc.) -Medications -Nutrition -At least one other area of pertinent information for the patient to have a successful discharge from the unit, and prevent readmission (you get to choose this). Ms. Kate a 76 year-old female who was admitted from the emergency department with a diagnosis of Right...
Please post screenshots of outputs. Also make sure to use stacks and queues. You will design...
Please post screenshots of outputs. Also make sure to use stacks and queues. You will design a program to keep track of a restaurants waitlist using a queue implemented with a linked list. Make sure to read pages 1215-1217 and 1227-1251 1. Create a class named waitList that can store a name and number of guests. Use constructors to automatically initialize the member variables. 2. Add the following operations to your program: a. Return the first person in the queue...
Please show all steps and write neatly. Make sure the proving is with letters and not...
Please show all steps and write neatly. Make sure the proving is with letters and not with numbers. Please!!!! Thank you Let A, B, C be 3 x 3 matrices. Show (AB)C= A(BC)
Please attach the output screenshots, narrative descriptions, or paste the Python codes. Please write code to...
Please attach the output screenshots, narrative descriptions, or paste the Python codes. Please write code to print the type of the following variables. Please write down the codes and the output as well. x = 3.5 y = '3.5' z = {1:'John', 2:'Wick', 3:'Barry', 4:'Allen'}
I need to know how to answer this question only in Excel. Please include instructions, screenshots,...
I need to know how to answer this question only in Excel. Please include instructions, screenshots, etc. in Excel which explain the process (formulas included). TropSun is a leading grower and distributer of fresh citrus products with three large citrus groves scattered around central Florida in the cities of Orlando, Eustis, and Winter Haven. TropSun currently has 275,000 bushels of citrus at the grove in Mt. Dora, 400,000 bushels at the groves in Eustis, and 300,000 bushels at the grove...
Please write the program in JAVA and provide me with the output screenshots!! Assignment Objectives •...
Please write the program in JAVA and provide me with the output screenshots!! Assignment Objectives • Be able to write methods • Be able to call methods Introduction Methods are commonly used to break a problem down into small manageable pieces. A large task can be broken down into smaller tasks (methods) that contain the details of how to complete that small task. The larger problem is then solved by implementing the smaller tasks (calling the methods) in the correct...
Make sure to include comments that explain all your steps (starts with #) Make sure to...
Make sure to include comments that explain all your steps (starts with #) Make sure to include comments that explain all your steps (starts with #) Write a program that prompts the user for a string (a sentence, a word list, single words etc.), counts the number of times each word appears and outputs the total word count and unique word count in a sorted order from high to low. The program should: Display a message stating its goal Prompt...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT