Question
From the code I wrote can you modify the program to do the following Prompt the user to input two integers: lower and upper (lower
From the code I wrote can you modify the program to do the following
Prompt the user to input two integers: lower and upper (lower must be less than upper).
Use a for loop to find and output all the multiples of 3 between lower and upper on the screen and write each number into a text file lab3data.txt. Separate each number by a space character.
Add statements to find the total number of multiples of 3 between lower and upper and output it on the screen.
Use a while loop to read all the numbers from lab3data.txt which you just wrote data in, find their sum, and output all the numbers and the sum on the screen.
Write loops to print out the following pattern:
import java.io.File; import java.io.FileNotFoundException; import java.io.PrintWriter; import java.util.Scanner;
public class Lab3 { public static void main(String [] args) throws FileNotFoundException{ int lower, upper; Scanner keyboard = new Scanner (System.in); System.out.println("Enter a lower bound integer: "); lower = keyboard.nextInt(); System.out.println("Enter an upper-bound integer: "); upper = keyboard.nextInt(); File file = new File("lab3data.txt"); PrintWriter outfile = new PrintWriter(file); System.out.println(lower); outfile.println(lower); //for loop outfile.close(); //Task 4 Scanner infile = new Scanner (file); int num = infile.nextInt(); System.out.println("Reading from file ..."+ num); infile.close(); } }
%%%%% % % %% % %% %Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started