Question

In: Computer Science

Sum the odd integers between 1 and 99 using a for structure. Assume the integer variables...

  1. Sum the odd integers between 1 and 99 using a for structure. Assume the integer variables sum and count have been declared.

  2. Calculate the value of 2.5 raised to the power of 3 using pow method.

  3. Print the integers from 1 to 20 using a while loop and the counter variable x. Assume that the variable x has been declared but not initialized. Print only five integers per line.[ Hint: Use calculation x % 5. When the value of this is 0, print a newline character; otherwise, print a tab character. Assume this is an application- use the System.out.println() method to output the newline character and use the System.out.print( ‘\t’ ) method to output the tab character.]

  4. Repeat Exercise 2 c) using for structure.

Solutions

Expert Solution

public class Calculation
{
    public static void main(String[] args)
    {
        int sum=0,i;
        for(i=3;i<99;i=i+2)
        {
            sum=sum+i;
        }
        System.out.println("Sum of odd integers between 1 to 99 is "+sum);
    }
}

----------------------------------------------------------------------------------------------------------------------------------------------------

public class Calculation
{
    public static void main(String[] args)
    {
       float base= (float) 2.5;
        double result;
        int exponent=3;
       result=Math.pow(base,exponent);
        System.out.println(result);
    }
}

----------------------------------------------------------------------------------------------------------------------------------

public class Calculation
{
    public static void main(String[] args)
    {
        int x=1;
       while(x<=20)
       {
           System.out.print(x);

           if(x%5==0)
           {
               System.out.println();
           }
           else
           {
               System.out.print('\t');
           }
           x++;
       }
    }
}

----------------------------------------------------------------------------------------------------------

public class Calculation
{
    public static void main(String[] args)
    {
        for(int x=1;x<=20;x++)
       {
           System.out.print(x);

           if(x%5==0)
           {
               System.out.println();
           }
           else
           {
               System.out.print('\t');
           }
       }
    }
}

***********************************************************************************************************************************


Related Solutions

Write a program that will calculate the sum of the first n odd integers, and the...
Write a program that will calculate the sum of the first n odd integers, and the sum of the first n even integers. Use a Do while loop Use a for loop Here is a sample of how the program should run: How many odd integers would you like to add? 5 Count Odd Integer Sum 1 1 1 2 3 4 3 5 9 4 7 16 5 9 25 The sum of the first 5 odd integers is...
(a) Can the sum of 12345 odd pos- itive integers be 12345678 ? Prove or disprove....
(a) Can the sum of 12345 odd pos- itive integers be 12345678 ? Prove or disprove. (b) Prove that for every possible re-arrangement (b1, b2, . . . , b999) of the numbers (1, 2, . . . , 999), the product (b1 − 1)(b2 − 2)(b3 − 3) · . . . · (b999 − 999) is even.
Write a program in C++ that computes the sum of odd numbers between 1 and 117....
Write a program in C++ that computes the sum of odd numbers between 1 and 117. Execute the program and submit a screen capture of the program and its results.
Question 1 Consider the following two Diophantine equations with integer variables X and Y (1) 99...
Question 1 Consider the following two Diophantine equations with integer variables X and Y (1) 99 X + 225 Y = 36 (2) 225 X + 99 Y = 33 (a) Determine which of these two equations is inconsistent, and explain why (you can use the Maple commands ifactor and/or gcd ). For the equation that is consistent, apply Extended Euclid's Algorithm to find a solution  {X0, Y0} . (b) Find now all solutions  {X, Y} of that equation, and identify the...
Write a Java program using using WHILE loop to find the sum of all integers between...
Write a Java program using using WHILE loop to find the sum of all integers between 200 to 250 which are divisible by 7. Sample Output: Numbers between 200 and 250, divisible by 7: 203 210 217 224 231 238 245 The sum is: 1568
Using C++, find the sum of the squares of the integers from 1 to MySquare, where...
Using C++, find the sum of the squares of the integers from 1 to MySquare, where MySquare is input by the user. Be sure to check that the user enters a positive integer.
Using for loop . Input an integer and identify whether it's EVEN OR ODD ( without...
Using for loop . Input an integer and identify whether it's EVEN OR ODD ( without using modulo operator ) using only <iostream> . C++ programming
1. Give a direct proof that if n is an odd integers, then n3 is also...
1. Give a direct proof that if n is an odd integers, then n3 is also an odd integer. 2. Give a proof by contradiction that the square of any positive single digit decimal integer cannot have more than two decimal digits.
Program – version 1: Sum of Range Algorithm Write a program that will sum the integers...
Program – version 1: Sum of Range Algorithm Write a program that will sum the integers between a given range (limit your range from 0 to 50). For example, if the user want to add the integers between (and including) 1 and 10, then the program should add: 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 Algorithm: Program title/description Ask the user to input a start value in the...
In Coral. Given a sorted list of integers, output the middle integer .Assume the number of...
In Coral. Given a sorted list of integers, output the middle integer .Assume the number of integers ia odd. Ex: if the input 2 3 4 8 11 -1(a negative indicates end), the output is 4. the maximum number of inputs for any test case should not exceed 9 positive values. If exceeded , output Too many inputs". Hint: Use an array of size 9. First read the data into array.Then,based in the number of items, find the middle item.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT