in java Write a few lines of code that will read the follow

in java

) Write a few lines of code that will read the following input using a Scanner. You may want to test your solution using a program to be sure it is correct.

The data below represents two runners and their times. Read it into the variables below using a Scanner object.

Abebe Bikila

34.8

Waldemar Fired Up Cierpinski

42.3

// variables declared below

String firstRunnerName;

double firstRunnerTime;

String secondRunnerName;

double secondRunnerTime;

Solution

public class OddEvenSum { // Save as \"OddEvenSum.java\" public static void main(String[] args) { int lowerbound = 1, upperbound = 1000; int sumOdd = 0; // For accumulating odd numbers, init to 0 int sumEven = 0; // For accumulating even numbers, init to 0 int number = lowerbound; while (number <= upperbound) { if (number % 2 == 0) { // Even sumEven += number; // Same as sumEven = sumEven + number } else { // Odd sumOdd += number; // Same as sumOdd = sumOdd + number } ++number; // Next number } // Print the result System.out.println(\"The sum of odd numbers from \" + lowerbound + \" to \" + upperbound + \" is \" + sumOdd); System.out.println(\"The sum of even numbers from \" + lowerbound + \" to \" + upperbound + \" is \" + sumEven); System.out.println(\"The difference between the two sums is \" + (sumOdd - sumEven)); } }
in java ) Write a few lines of code that will read the following input using a Scanner. You may want to test your solution using a program to be sure it is corr

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site