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: Intro. to Prob. Solv... (Looseleaf)
Additional Engineering Textbook Solutions
Web Development and Design Foundations with HTML5 (9th Edition) (What's New in Computer Science)
Starting Out with C++: Early Objects
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Starting Out With Visual Basic (7th Edition)
Database Concepts (8th Edition)
- What is the output of the following code segment?inte=5,f=10;if(eff0)Write(Purple) inte=5,f=10;if(eff0)Write(Purple) else Write(Gold); Purple Gold PurpleGold nothingarrow_forwardHow do I write a char int so that it can hold multiple different of the same variable like I want it Gender to be able to be F, f, Female, and her.arrow_forwardWrite a program that generates 3 random integers exam scores 50-100 and will print the largest score and the averagearrow_forward
- Write code that outputs variable numDogs as follows. End with a newline. Ex: If the input is: 3 the output is: Dogs: 3 I tried to get the output of 6 by its wrong everytime.arrow_forwardThe last line of the code, is there something missing on it? The last line says, "move $v0, "arrow_forwardUse two appropriate methods of String class to check if they are equal. The output of first method should be that they are not equal. And the output of the second method should be that they are equal. Partial code is given below to help you complete this question. You can ignore this entirely and write your..arrow_forward
- Write a program that promotes the user to enter the number of students and each student's name and score ,and finally displays the student with the highest score and the second highest score.arrow_forwardIn the following code stream, identify if there are any hazards. Crisply describe if it is possible to get around the hazards, and what the resulting steps will be. lw r2, 0(r1) add r3, r2, r3 sub r1, r1, r4arrow_forwardWrite a program that randomly generates an integer between 1and 12 and displays the English month names January, February, . . . , Decemberfor the numbers 1, 2, . . . , 12, accordingly.arrow_forward
- What is the output of the code segment below? Hint: Draw a 2x3 grid and then fill it in. int[][] plot = new int[2][3]; for (int s = 0; s < 2; s++) for (int t = 0; t < 3; t++) plot[s][t] = t - s + 3; for (int s = 0; s < 2; s++) { int sum = 0; for (int t = 0; t < 3; t++) sum += plot[s][t]; System.out.print(sum + " "); }arrow_forwardWrite a program that prompts the capacity, in gallons, of an automobile fuel tank and the miles per gallon theautomobile can be driven without refueling.arrow_forwardThis Code print the first occurrences of x, Modify the code to print the last occurrences of x and print how many times it exists? ( with explanation for each line if possible) many thanks.arrow_forward
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,