Starting Out with Java: From Control Structures through Objects (6th Edition)
6th Edition
ISBN: 9780133957051
Author: Tony Gaddis
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Expert Solution & Answer
Chapter 4, Problem 4FTE
Explanation of Solution
The given program is used to display the “count” value by using “for” condition.
Syntax error:
An error which occurs on the source code of a program is referred to as a “syntax error” because the computer programs strictly follow the syntax rules. If the code fails to prove its language syntax format, then the compiler will throw an error.
Error #1:
The initialization and test expressions should be terminated with semicolons, not commas...
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Language: JAVA
Leap-Year
Write a program to find if a year is a leap year or not. We generally assume that if a year number is divisible by 4 it is a leap year. But it is not the only case. A year is a leap year if −
It is evenly divisible by 100
If it is divisible by 100, then it should also be divisible by 400
Except this, all other years evenly divisible by 4 are leap years.
So the leap year algorithm is, given the year number Y,
Check if Y is divisible by 4 but not 100, DISPLAY "leap year"
Check if Y is divisible by 400, DISPLAY "leap year"
Otherwise, DISPLAY "not leap year"
For this program you have to take the input, that is the year number from an input file input.txt that is provided to you. The input file contains multiple input year numbers. Use a while loop to input the year numbers from the input file one at a time and check if that year is a leap year or not.
Create a class named LeapYear which will contain the main method and write all your code in the main…
- Transposed matrixImplement a program that calculates the transpose of a matrix entered by the user.- Conway's Game of LifeCreates a simulation of Conway's Game of Life in a 10x10 matrix, where the initial state is entered by the user.do it in "c" programming language
C programming language question
Chapter 4 Solutions
Starting Out with Java: From Control Structures through Objects (6th Edition)
Ch. 4.1 - What will the following program segments display?...Ch. 4.2 - How many times will Hello World be printed in the...Ch. 4.2 - How many times will I love Java programming! be...Ch. 4.3 - Write an input validation loop that asks the user...Ch. 4.3 - Write an input validation loop that asks the user...Ch. 4.3 - Write an input validation loop that asks the user...Ch. 4.5 - Name the three expressions that appear inside the...Ch. 4.5 - You want to write a for loop that displays I love...Ch. 4.5 - What will the following program segments display?...Ch. 4.5 - Write a for loop that displays your name 10 times.
Ch. 4.5 - Write a for loop that displays all of the odd...Ch. 4.5 - Write a for loop that displays every fifth number,...Ch. 4.6 - Write a for loop that repeats seven times, asking...Ch. 4.6 - In the following program segment, which variable...Ch. 4.6 - Prob. 4.15CPCh. 4.10 - What is the difference between an input file and...Ch. 4.10 - What import statement will you need in a program...Ch. 4.10 - What class do you use to write data to a file?Ch. 4.10 - Write code that does the following: opens a file...Ch. 4.10 - What classes do you use to read data from a file?Ch. 4.10 - Write code that does the following: opens a file...Ch. 4.10 - You are opening an existing file for output. How...Ch. 4.10 - What clause must you write in the header of a...Ch. 4.11 - Assume x is an int variable, and rand references a...Ch. 4.11 - Assume x is an int variable, and rand references a...Ch. 4.11 - Assume x is an int variable, and rand references a...Ch. 4.11 - Assume x is a double variable, and rand references...Ch. 4 - What will the println statement in the following...Ch. 4 - Prob. 2MCCh. 4 - Prob. 3MCCh. 4 - What is each repetition of a loop known as? a....Ch. 4 - This is a variable that controls the number of...Ch. 4 - The while loop is this type of loop. a. pretest b....Ch. 4 - The do-while loop is this type of loop. a. pretest...Ch. 4 - The for loop is this type of loop. a. pretest b....Ch. 4 - This type of loop has no way of ending and repeats...Ch. 4 - This type of loop always executes at least once....Ch. 4 - This expression is executed by the for loop only...Ch. 4 - Prob. 12MCCh. 4 - This is a special value that signals when there...Ch. 4 - To open a file for writing, you use the following...Ch. 4 - To open a file for reading, you use the following...Ch. 4 - Prob. 16MCCh. 4 - This class allows you to use the print and println...Ch. 4 - This class allows you to read a line from a file....Ch. 4 - True or False: The while loop is a pretest loop.Ch. 4 - True or False: The do-while loop is a pretest...Ch. 4 - True or False: The for loop is a posttest loop.Ch. 4 - True or False: It is not necessary to initialize...Ch. 4 - True or False: One limitation of the for loop is...Ch. 4 - True or False: A variable may be defined in the...Ch. 4 - True or False: In a nested loop, the inner loop...Ch. 4 - True or False: To calculate the total number of...Ch. 4 - // This code contains ERRORS! // It adds two...Ch. 4 - Prob. 2FTECh. 4 - // This code contains ERRORS! int choice, num1,...Ch. 4 - Prob. 4FTECh. 4 - Write a while loop that lets the user enter a...Ch. 4 - Write a do-whi1e loop that asks the user to enter...Ch. 4 - Write a for loop that displays the following set...Ch. 4 - Write a loop that asks the user to enter a number....Ch. 4 - Write a for loop that calculates the total of the...Ch. 4 - Write a nested loop that displays 10 rows of #...Ch. 4 - Convert the while loop in the following code to a...Ch. 4 - Convert the do-while loop in the following code to...Ch. 4 - Convert the following while loop to a for loop:...Ch. 4 - Convert the following for loop to a while loop:...Ch. 4 - Write an input validation loop that asks the user...Ch. 4 - Write an input validation loop that asks the user...Ch. 4 - Write nested loops to draw this pattern:Ch. 4 - Write nested loops to draw this pattern: ## # # #...Ch. 4 - Complete the following program so it displays a...Ch. 4 - Complete the following program so it performs the...Ch. 4 - Prob. 17AWCh. 4 - Prob. 18AWCh. 4 - Modify the code you wrote in Question 18 so it...Ch. 4 - Write code that opens a file named NumberList.txt...Ch. 4 - Prob. 1SACh. 4 - Why should you indent the statements in the body...Ch. 4 - Describe the difference between pretest loops and...Ch. 4 - Why are the statements in the body of a loop...Ch. 4 - Describe the difference between the while loop and...Ch. 4 - Which loop should you use in situations where you...Ch. 4 - Which loop should you use in situations where you...Ch. 4 - Which loop should you use when you know the number...Ch. 4 - Why is it critical that accumulator variables are...Ch. 4 - What is an infinite loop? Write the code for an...Ch. 4 - Describe a programming problem that would require...Ch. 4 - What does it mean to let the user control a loop?Ch. 4 - What is the advantage of using a sentinel?Ch. 4 - Prob. 14SACh. 4 - Describe a programming problem requiring the use...Ch. 4 - How does a file buffer increase a programs...Ch. 4 - Why should a program close a file when its...Ch. 4 - What is a files read position? Where is the read...Ch. 4 - When writing data to a file, what is the...Ch. 4 - What does the Scanner classs hasNext method return...Ch. 4 - What is a potential error that can occur when a...Ch. 4 - Prob. 22SACh. 4 - How do you open a file so that new data will be...Ch. 4 - Sum of Numbers Write a program that asks the user...Ch. 4 - Distance Traveled The distance a vehicle travels...Ch. 4 - Distance File Modify the program you wrote for...Ch. 4 - Pennies for Pay Write a program that calculates...Ch. 4 - Prob. 5PCCh. 4 - File Letter Counter Write a program that asks the...Ch. 4 - Hotel Occupancy A hotels occupancy rate is...Ch. 4 - Average Rainfall Write a program that uses nested...Ch. 4 - Population Write a program that will predict the...Ch. 4 - Largest and Smallest Write a program with a loop...Ch. 4 - Celsius to Fahrenheit Table Write a program that...Ch. 4 - Bar Chart Write a program that asks the user to...Ch. 4 - File Head Display Write a program that asks the...Ch. 4 - Line Numbers Write a program that asks the user...Ch. 4 - Uppercase File Converter Write a program that asks...Ch. 4 - Budget Analysis Write a program that asks the user...Ch. 4 - Random Number Guessing Game Write a program that...Ch. 4 - Random Number Guessing Game Enhancement Enhance...Ch. 4 - ESP Game Write a program that tests your ESP...Ch. 4 - Square Display Write a program that asks the user...Ch. 4 - Dice Game Write a program that plays a simple dice...Ch. 4 - Prob. 22PC
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- (Numerical) Write and test a function that returns the position of the largest and smallest values in an array of double-precision numbers.arrow_forwardConsider the following pseudo code, Method func() { PRINT “This is recursive function" func() } Method main( { func() } What will happen when the above snippet is executed?arrow_forwardRacket code only please - primeTest It takes as input any positive integer n and returns true if the absolute value of the polynomial 8n2 − 488n + 7243 is a prime number. For example, the invocation (primeTest 5) should return true. - primeTestSeq This takes two arguments, a low bound and an upper bound. It determines what percentage of the integers between the lower bound and the upperbound are, according to primeTest, a prime number. For example, the invocation (primeTestSeq 1 60) should return 100.arrow_forward
- C++ Code: This function will print out the information that has been previously read (using the function readData) in a format that aligns an individual's STR counts along a column. For example, the output for the above input will be: name Alice Bob Charlie ---------------------------------------- AGAT 5 3 6 AATG 2 7 1 TATC 8 4 5 This output uses text manipulators to left-align each name and counts within 10 characters. The row of dashes is set to 40 characters. /** * Computes the longest consecutive occurrences of several STRs in a DNA sequence * * @param sequence a DNA sequence of an individual * @param nameSTRs the STRs (eg. AGAT, AATG, TATC) * @returns the count of the longest consecutive occurrences of each STR in nameSTRs **/ vector<int> getSTRcounts(string& sequence, vector<string>& nameSTRs) For example, if the sequence is AACCCTGCGCGCGCGCGATCTATCTATCTATCTATCCAGCATTAGCTAGCATCAAGATAGATAGATGAATTTCGAAATGAATGAATGAATGAATGAATGAATG and the vector namesSTRs is…arrow_forwardLucky Customer Code in C Languagearrow_forwardClass: Blocks Write a program that prompts for an integer (that a side length) and displays, using asterisks, a filled and hollow square, placed next to each other. For example if the side length is 5, the program should display: ***** ********** * ****** * ****** * ****** *****arrow_forward
- #include void main () { int a=5,b=10,c=1; if (a && b>c) { printf("cquestionbank"); } else{ break; } }arrow_forward#include <stdio.h>#include <stdlib.h> //declaring variables globally to calculate coinsint cent50 = 0;int cent20 = 0;int cent10 = 0;int cent05 = 0; //calculate change//pass change variable by addressvoid calculateChange(int* change) {//calculate change only if change is positiveif(*change > 0) {if(*change >= 50) {*change -= 50;cent50++;}else if(*change >= 20) {*change -= 20;cent20++;}else if(*change >= 10) {*change -= 10;cent10++;}else if(*change >= 05) {*change -= 05;cent05++;}//call calculateChange recursively calculateChange(change);}} // function to display the cents valuesvoid printChange() { if(cent50)printf("\n50 Cents : %d coins", cent50);if(cent20)printf("\n20 Cents : %d coins", cent20);if(cent10)printf("\n10 Cents : %d coins", cent10);if(cent05)printf("\n05 Cents : %d coins", cent05);//reset all cent variables with 0cent50 = 0;cent20 = 0;cent10 = 0;cent05 = 0; } //take change input from user//change variable passed addressvoid TakeChange(int*…arrow_forwardRest of code in image / This is a bad programming style since it is using goto. // This is an spagetti code and not working.// Use function to display menu, and display game rules,// Use different color for text display.// fix it so it works any way you like./*HANDLE screen = GetStdHandle(STD_OUTPUT_HANDLE); // Write 16 lines in 16 different colors. for (int color = 0; color < 16; color++) { SetConsoleTextAttribute (screen, color); cout << " Hello World!" << endl; Sleep(400); // Pause between lines to watch them appear } // Restore the normal text color) SetConsoleTextAttribute(screen, 7);*/#include <iostream>#include <windows.h>using namespace std;int main(){ //textbackground(WHITE); //textcolor(RED); system("cls"); char ch, a[20], ch2; int num = 100, rnum, guess, count, ch1, c = 0; cout << "**********************************************************"<<endl; cout << "*…arrow_forwardJAVA CODE ONLY AND PROVIDE OUTPUT SCREENSHOT PLEASEarrow_forwardDirection: Read each sentence/ situation carefully and select the BEST answer among the choices. 1. It is a Boolean expression that tells when the loop will exit. 2. The sequence that makes up the loop body may either be a block of Turbo C statements or a single Turbo C statement. 3. In Turbo C it is a reserved word. 4. Its values determine the number of times the loop iterates. 5. It is the second type of open-ended loop. Condition For Loop Statement For Do while Looparrow_forwardarrow_back_iosSEE MORE QUESTIONSarrow_forward_ios
Recommended textbooks for you
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning