1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
dusya [7]
3 years ago
7

In Java.Use a single for loop to output odd numbers, even numbers, and an arithmetic function of an odd and even number. Use the

numbers in the range [ 0, 173 ]. Note that the square brackets indicate inclusion of the endpoints. 0 (zero) is considered an even number. Format your output to 4 decimal places.Do not use any branching statements (if, if-else, switch, ... )Your output should be professional in appearance and formatted. Use at least one control character in your output other than '\n'.Document your code.Using your loop, display the following in a single line on the console:Odd number even number sqrt( odd number + even number)Your output should look like this (this is a partial example for the numbers [0, 173].1.0000 3.0000 5.0000 7.00000.0000 2.0000 4.0000 6.00001.0000 2.2361 3.0000 3.6051
Computers and Technology
1 answer:
rosijanka [135]3 years ago
7 0

Answer:

<em>This program is written using java programming language</em>

<em>Difficult lines are explained using comments (See Attachment for Source file)</em>

<em>Program starts here</em>

import java.util.*;

import java.lang.Math;

public class oddeven{

public static void main(String [] args)

{

 double even,odd;//Declare variables even and odd as double

 //The next iteration prints odd numbers

 for(int i = 1;i<=173;i+=2)

 {

  odd = i;

  System.out.format("%.4f",odd);//Round to 4 decimal places and print

System.out.print("\t");

 }

 System.out.print('\n');//Start printing on a new line

 //The next iteration prints even numbers

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

 {

  even=i;

  System.out.format("%.4f",even);//Round to 4 decimal places and print

System.out.print("\t");

 }

 System.out.print('\n');//Start printing on a new line

 double  ssqrt;//Declare ssqrt to calculate the square root of sum of even and odd numbers

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

 {

  ssqrt = Math.sqrt(2*i+1);//Calculate square root here

  System.out.format("%.4f",ssqrt); //Round to 4 decimal places and print

System.out.print("\t");

 }

}

}

Explanation:

Libraries are imported into the program

import java.util.*;

import java.lang.Math;

The following line declares variables even and odd as double

double even,odd;

The following iteration is used to print odd numbers  with in the range of 0 to 173

for(int i = 1;i<=173;i+=2)  {

odd = i;

System.out.format("%.4f",odd); This particular line rounds up each odd numbers to 4 decimal places before printing them

System.out.print("\t"); This line prints a tab

}

The following code is used to start printing on a new line

System.out.print('\n');

The following iteration is used to print even numbers  with in the range of 0 to 173

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

{

even=i;

System.out.format("%.4f",even); This particular line rounds up each even numbers to 4 decimal places before printing them

System.out.print("\t"); This line prints a tab

}

The following code is used to start printing on a new line

System.out.print('\n');

The next statement declares ssqrt as double to calculate the square root of the sum of even and odd numbers

double  ssqrt;

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

{

ssqrt = Math.sqrt(2*i+1);This line calculates the square root of sum of even and odd numbers

System.out.format("%.4f",ssqrt); This particular line rounds up each even numbers to 4 decimal places before printing them

System.out.print("\t"); This line prints a tab

}

Download java
You might be interested in
When you divide a picture into thirds, how many parts do you end up with? *
lara31 [8.8K]

Answer:

3

Explanation:

6 0
3 years ago
Read 2 more answers
Where are parameters such boot order, processor voltage, motherboard raid, hardware virtualization support, and overclocking con
ololo11 [35]

This is configured on the BIOS Setup. During computer start-up usually for windows system this can be accessed via pressing on ESC or Function keys on immediate start up.

6 0
2 years ago
In this lab, you use the flowchart and pseudocode found in the figures below to add code to a partially created C++ program. Whe
never [62]

Answer:

The equivalent program in C++:

#include<iostream>

#include <sstream>

using namespace std;

int main(){

   string Score, Rank;

   cout<<"Enter student score and class rank: ";

   cin>>Score>>Rank;

   int testScore = 0, classRank = 0;

   stringstream sstream(Score);

   sstream>>testScore;

   

   stringstream tream(Rank);

   tream>>classRank;

   

   if (testScore >= 90){

       if(classRank >=25){cout<<"Accept";}

       else{cout<<"Reject";}

   }

   else if(testScore >= 80){

       if(classRank >=50){cout<<"Accept";}

       else{cout<<"Reject";}

   }

   else if(testScore >= 70){

       if(classRank >=75){cout<<"Accept";}

       else{cout<<"Reject";}

   }

   else{cout<<"Reject";}

   return 0;

}

Explanation:

This declares Score and Rank as string variables

   string Score, Rank;

This prompts the user for score and class rank

   cout<<"Enter student score and class rank: ";

This gets the user input

   cin>>Score>>Rank;

This declarees testScore and classRank as integer; and also initializes them to 0

   int testScore = 0, classRank = 0;

The following converts string Score to integer testScore

<em>    stringstream sstream(Score);</em>

<em>    sstream>>testScore;</em>

The following converts string Rank to integer classRank

   stringstream tream(Rank);

   tream>>classRank;

The following conditions implement the conditions as given in the question.    

If testScore >= 90

<em>    if (testScore >= 90){</em>

If classRank >=25

<em>        if(classRank >=25){cout<<"Accept";}</em>

If otherwise

<em>        else{cout<<"Reject";}</em>

<em>    } ---</em>

If testScore >= 80

<em>    else if(testScore >= 80){</em>

If classRank >=50

<em>        if(classRank >=50){cout<<"Accept";}</em>

If otherwise

<em>        else{cout<<"Reject";}</em>

<em>    }</em>

If testScore >= 70

<em>    else if(testScore >= 70){</em>

If classRank >=75

<em>        if(classRank >=75){cout<<"Accept";}</em>

If otherwise

<em>        else{cout<<"Reject";}</em>

<em>    }</em>

For testScore less than 70

<em>    else{cout<<"Reject";}</em>

<em />

3 0
2 years ago
What does a file extension tell you?
kiruha [24]

A. because everyone basically has seen it..

3 0
2 years ago
When data are entered into a form and saved, they are placed in the underlying database as knowledge?
luda_lava [24]
The answer would be and is true.
7 0
2 years ago
Other questions:
  • Unix has experimented with several security programs. a user can attach a watchdog program to a file that grants or denies acces
    13·1 answer
  • How many computers/laptop's suported windows 10 pro with a game in vr?
    9·2 answers
  • Name three types of hard drives, along with its speed and size.
    8·1 answer
  • Hi, I just have a few questions from my digital tech assignment.
    14·2 answers
  • Explain how the use of Git and a shared public Git repository simplifies the process of managing opensource development when man
    8·1 answer
  • How are programs and algorithms related? A program is a part of an algorithm. They are not connected at all. An algorithm is a p
    12·1 answer
  • Bonjour ma question est: expliquer comment fonctionne une calculatrice qui ne contient pas une pile. Pouvez-vous m'aider?
    12·1 answer
  • The software concept ___________and defines a need for the new system.
    6·1 answer
  • Range paramters - for loop<br> question in picture
    13·1 answer
  • A security operation center (SOC) analyst investigates the propagation of a memory-resident virus across the network and notices
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!