Explanation of Solution
Step 1: First get the number of free block and store it in a variable “blocks”.
Step 2: Assign “true” to a Boolean variable “flag”.
Step 3: WHILE “flag”.
Step 4: Get the size of the file in bytes and store it in a variable “size”.
Step 5: Calculate the compressed size of the file and store it in a variable “compress”.
Step 6: Calculate number of blocks required for the file and store it in a variable “blocksNeeded”. This is done by dividing “compress” by 512.
Step 7: Check if the “blocksNeeded” is less than “blocks”.
Step 8: If the condition is true then reduce the number of free blocks. This is done by subtracting “blocksNeeded” from “blocks”.
Step 9: If the condition is false then assign “false” to the variable “flag”.
Complete program:
//Import required packages
import static java.lang.Math.round;
import java.util.*;
//Define the main class
public class FileSize
{
//Define the main method
public static void main(String[] args)
{
//Declare required variables
double blocks, size;
boolean flag = true;
//Create an object for scanner class
Scanner sc = new Scanner(System.in);
//Get the number of free blocks
System.out.print("Enter the number of free blocks: ");
blocks = sc.nextInt();
//While true
while(flag)
{
//Declare required variables
double compress = 0, blocksNeeded = 0;
//Get the size of the file
System.out.print("\nEnter the size of file in bytes: ");
size = sc...
Want to see the full answer?
Check out a sample textbook solutionChapter 4 Solutions
Java: An Introduction to Problem Solving and Programming (8th Edition)
- Integer numInput is read from input. Write a while loop that iterates until numInput is negative. At each iteration: Update integer result as follows: If numInput is even, subtract numInput from result. Otherwise, add numInput to result. Then, read an integer from input into variable numInput. End each output with a newline. Ex: If the input is 6 2 5 -5, then the output is: Result is -3 Note: x % 2 == 0 returns true if x is even. #include <iostream>using namespace std; int main() { int numInput; int result; result = 0; cin >> numInput; /* Your code goes here */ cout << "Result is " << result << endl; return 0;}arrow_forwardAssignment for Computer Architecture You are to write a program in MIPS that computes N! using a loop. Remember N! is the product of all the numbers from 1 to N inclusive, that is 1 x 2 x 3 x (N – 1) x N. It is defined as 1 for N = 0 and is undefined for values less than 0. The program first requests the user to input the value of N (display a prompt first so the user knows what to do). If the input value is less than 0, the program is to display “N! undefined for values less than 0” and request input again. If the value input is non-negative, it is to compute N! using a loop. You are to have your name, the assignment number, and a brief description of the program in comments at the top of your program. Since this is an assembly language program, I expect to see comments on almost every line of code in the program. Also make the code neat (line up the commands and comments in nice columns)arrow_forwardpython Write a program that uses a text file to store the days and hours that a user worked in a week. The program should begin by prompting for the number of days worked in the week. It should continue with a loop for input of the days and hours and for writing these to the file, each on its own line. Sample Output (inputs shown in boldface)How many days did you work this week? 5Enter day of week MondayHow many hours did you work on Monday? 10Enter day of week TuesdayHow many hours did you work on Tuesday? 8Enter day of week WednesdayHow many hours did you work on Wednesday? 12Enter day of week FridayHow many hours did you work on Friday? 12Enter day of week SaturdayHow many hours did you work on Saturday? 8File was createdarrow_forward
- Subject: Assembly Language Q: Write a program that displays a string in all possible combinations of foreground and background colors (16 x 16 =256). The colors are numbered from 0 to 15, so you can use a nested loop to generate all possible combinations. Also use a delay of 1s in each foreground color change.arrow_forwardConstruct a while() loop in programming language c, which prints only the even integer numbers in the range n downto 2. Where n is an integer entered by the user. You may assume that n > 1. Show all variable declarations and the prompt for n, along with the appropriate loop. If n is 7, then the output should look like: 6 4 2arrow_forwardDemonstrate a do-while loop program that asks the user to enter two numbers. The numbers should be added and the sum displayed. The loop should ask the user whether he or she wishes to perform the operation again. If so, the loop should repeat; otherwise it should terminate.arrow_forward
- 1. Write a program that uses one loop to process the integers from 300 down to 200, inclusive. The program should detect multiples of 11 or 13, but not both. The multiples should be printed left-aligned in columns 8 characters wide, 5 multiples per line (See Example Output). When all multiples have been displayed, the program should display the number of multiples found and their sum. Example Output 299 297 275 273 264 260 253 247 242 234 208 231 221 220 209 Found ?? integers totaling ??arrow_forwardComplete the program to increment only the odd content of the memory locations from 0x600 to 0x645 LDI XL 0x00 LDI loop: 0 LDI R16, DEC Ox45 || SBIC R20, P R20 R20 7 R20 JMP SBRC Ox600x46 R20 ST X 0x06 INC X+ SBRS R16 SBIS loop XH LD BRNEarrow_forward12. In .............., the bodies of the two loops are merged together to form a single loop provided that they do not make any references to each other. a. Loop unrolling b. Strength reduction c. Loop concatenation d. Loop jammingarrow_forward
- 2. Write a while loop program that accepts numbers, then identify which of the numbers entered is the highest and the lowest and get the sum of all numbers. The user should input the count of numbers to be entered. Sample Output: Enter the count of numbers to be entered: 5 5 8. The highest number is: 9 3 The lowest number is : 3 9. The sum of all numbers is: 31 6 3. Write a program that accepts two input numbers and compute the Greatest Common Divisor using do-while To get the GCD of another input number, type Y or y; otherwise, type N or n to quit the program. Sample Output: Enter the value of the first number: 10 Enter the value of the second number: The Greatest Common Divisor of 10 and 6 is 2 Type Y/y if you want to try again. Type N/n to exit. :arrow_forwardAim Using a for loop and a range function, you have been asked to find the even numbers between 5 and 55 and then find their sum. Steps for Completion 1. Define a counter for the sum named total_sum. 2. Define a for loop with an even range for numbers between 5 and 55. 3. Add each looped number to the sum. 4. Outside the loop, print out total_sum. The output should be as shown in Snippet 3.50: 750 Snippet 3.50arrow_forwardGeneral Instructions: Use code blocks or online compiler to do the given program.Write/copy paste the program in the space provided or upload the file. Write a program that accepts 10 integers from the user using loops and then displays the product of numbers which are less than 4 and product of numbers which are greater than 8. IN Sample Output: Enter a number 1 : 1 Enter a number 2 : 2 Enter a number 3 : 3 Enter a number 4: 4 Enter a number 5:5 Enter a number 6: 6 Enter a number 7: 7 Enter a number 8: 8 Enter a number 9: 9 Enter a number 10: 99 Product of numbers less than 4 is 6 Product of numbers greater than 8 is 891arrow_forward
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning