
Write a fragment of code that will test whether an integer variable score contains a valid test score. Valid test scores are in the range 0 to 100.

Program plan:
- • Include necessary header files.
- • Define the class “Fragments”.
- • Define the “main()” function.
- ○ Declare and initialize the necessary variables.
- ○ The “if” statement check the condition.
- ■ True, print the valid statement.
- ○ Otherwise, print the invalid statement.
Program to display the valid test score.
Explanation of Solution
Program:
//Import necessary header files
import java.util.*;
//Define the class
class Fragments
{
//Define the main() method
public static void main(String[] args)
{
//Initialize the variable
int score = 10;
//Check the condition
if( score >= 0 && score <= 100 )
{
//True, print the statement
System.out.println("The score " + score + " is valid.");
}
//Otherwise
else
{
//Print the statement
System.out.println("The score " + score + " is not valid.");
}
}
}
Output:
The score 10 is valid.
Want to see more full solutions like this?
Chapter 3 Solutions
Java: An Introduction to Problem Solving and Programming (8th Edition)
Additional Engineering Textbook Solutions
Problem Solving with C++ (10th Edition)
Starting Out with Python (4th Edition)
SURVEY OF OPERATING SYSTEMS
INTERNATIONAL EDITION---Engineering Mechanics: Statics, 14th edition (SI unit)
Elementary Surveying: An Introduction To Geomatics (15th Edition)
Starting Out With Visual Basic (8th Edition)
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
- Programming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage LearningProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageEBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT




