Question: import java.util.Scanner; /* * This program reads integer numbers from a scanner. If the number is between the limit numbers a and b and the

import java.util.Scanner;
/*
* This program reads integer numbers from a scanner. If the number is between the limit numbers a and b and the number is odd, then add this number to a total
*  
*/
public class SumOfOddNumbers
{
public static void main(String[] args)
{
 String aAndb = "20 60 1 30 70 90";
 Scanner ab = new Scanner(aAndb);
 
 String numbers = "7 67 23 18 16 99 45 51 42 64 33 71";    


 while (ab.hasNextInt())
 {  
    int a = ab.nextInt();
int b = ab.nextInt();

Scanner in = new Scanner(numbers);
int sum = 0;
//-----------Start below here. To do: approximate lines of code = 5
// Use a while loop, check for another integer num using Scanner in (hint: in.hasNextInt())
// Get the next int and assign to variable. Use an if statement to check if the number is between a and b and is odd.
// If so, add to the sum variable










//-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions.
System.out.println("The sum is " + sum);
}
 System.out.println("Expected:");
 System.out.println("The sum is 152");
 System.out.println("The sum is 30");
 System.out.println("The sum is 71");
}
}

Step by Step Solution

3.41 Rating (157 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

import javautilScanner This program reads integer numbers from a scanner If the ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!