Question

(Java) Write a code segment that uses a for loop and an in a statement to...

(Java) Write a code segment that uses a for loop and an in a statement to determine whether the value 13 is stored in a previously declared dimensional array named sportsScores. If the value 13 is stored in the array, then store the value true in a boolean flag variable named found. Otherwise, store false in found. The array sportsScores has 4 columns and 5 rows.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

//Java code

public class Main {
    public static void main(String[] args)
    {
        //The array sportsScores has 4 columns and 5 rows.
        int[][] sportsScores = new int[][]{
                {4,5,6,7},
        {3,4,5,6},
        {7,8,9,10},
        {5,3,2,1},
        {13,12,11,11}
            };
        boolean isContains13 = findValue(sportsScores);
        System.out.println("sportsScores array contains 13: "+isContains13);
    }

    /**
     * code segment that uses a for loop
     * and an in a statement to determine
     * whether the value 13 is stored in a
     * previously declared dimensional array
     * named sportsScores. If the value 13 is
     * stored in the array, then store the value
     * true in a boolean flag variable named found.
     * Otherwise, store false in found
     * @param sportsScores
     * @return
     */
    private static boolean findValue(int[][] sportsScores )
    {
        boolean found = false;
        for (int i = 0; i <sportsScores.length ; i++) {
            for (int j = 0; j <sportsScores[i].length; j++) {
                if(sportsScores[i][j]==13)
                    found = true;
            }
        }
        return found;
    }
}

//Output

//If you need any help regarding this solution...... please leave a comment..... thanks

Add a comment
Know the answer?
Add Answer to:
(Java) Write a code segment that uses a for loop and an in a statement to...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a java code that Declares and initialize a two-dimensional int array named grades. It should...

    Write a java code that Declares and initialize a two-dimensional int array named grades. It should have 10 rows and 6 columns where it stores the values and then calculates the average of all the elements in the grades array that you have declared

  • I am working on my java but I keep getting this one wrong. Method Name: arrayContains...

    I am working on my java but I keep getting this one wrong. Method Name: arrayContains Access modifier: Private Parameters: 1 integer named number Return type: boolean Purpose: This method returns a true or a false indicating if the number is present in an array or not. In order for this method to work, there must be an array already declared. Therefore, in the CLASS BLOCK, declare an array as follows: static int[] listof Numbers = {1, 2, 3, 4,...

  • I need to write a loop that examines the names of the cities stored in the...

    I need to write a loop that examines the names of the cities stored in the array. Write code that tests for a match Write code that, when appropriate, prints the message: Not a city in Illinois _______________________________________________________________ ' IllinoisCities.vb - This program prints a message for invalid cities in Illinois. ' Input: Interactive ' Output: Error message or nothing Option Explicit On Option Strict On Module IllinoisCities    Sub Main()       ' Declare variables.         Dim city As String                 ...

  • Write Java code to implement a FSM machine that recognizes the language for the alphabet {a,b,c} ...

    Write Java code to implement a FSM machine that recognizes the language for the alphabet {a,b,c} consisting of all strings that contain two consecutive c's and end with b.                   Your FSM program should include the following three static methods (Java) or functions (C):                                           a.    int nextState(int state, char symbol)                                  A state-transition function that returns the next state based on the                                  current state and an input symbol. This function should also return                                  -1 when an invalid input character is detected.                                  State...

  • visual basic help DI Question 3 2 pts You may only bind an object to a control that the computer creates for you O True O False D | Question 4 2 pts The Do..Loop statement can be used to code b...

    visual basic help DI Question 3 2 pts You may only bind an object to a control that the computer creates for you O True O False D | Question 4 2 pts The Do..Loop statement can be used to code both a pretest loop and a posttest loop. True False Question 5 2 pts You can prevent many unintentional errors from occurring in an application by declaring the variables using the maximum scope needed. True False 2 pts Question...

  • please do all in C++ code, thank you. Worth 1 point Checkpoint 7.12 Write a statement...

    please do all in C++ code, thank you. Worth 1 point Checkpoint 7.12 Write a statement that assigns the value 10 to the first elementof an array of integers named minutes. Type your program submission here Worth 1 point Checkpoint 7.14 Write a cout statement that will display contents of the second element of an array named courseNumbers Type your program submission here Submit Worth 1 point Checkpoint 7.15 Write a cin statement that will store the user's input in...

  • create a new Java application called "Scorer" (without the quotation marks) that declares a two-dimensional array...

    create a new Java application called "Scorer" (without the quotation marks) that declares a two-dimensional array of doubles (call it scores) with three rows and three columns and that uses methods and loops as follows. Use a method containing a nested while loop to get the nine (3 x 3) doubles from the user at the command line. Use a method containing a nested for loop to compute the average of the doubles in each row. Use a method to...

  • Java basic programming course simple as possible use java import and comments to explain the code...

    Java basic programming course simple as possible use java import and comments to explain the code thanks in advance Preezing and Bolling Points The following cable lisrs the freezing and boiling points of several substanices. Substance Ethyl Alcohol Oxygen -173 -362 32 Boiling Point 172 -306 212 ter Design a class that stores a temperature in a temperature field and has the appropriate accessor and mutator methods for the field. In addition to appropriate constructors, the class should have the...

  • Note: According to the question, please write source code in java only using the class method....

    Note: According to the question, please write source code in java only using the class method. Sample Run (output) should be the same as displayed in the question below. Make sure the source code is working properly and no errors. Exercise #2: Design and implement a program (name it compareArrays) that compares the content of 2 single-dimensional arrays of the same size. The program prompts the users to enter the array size. Then prompts the user to initialize each array...

  • Write a piece of code that constructs a two-dimensional array of integers with 5 rows and...

    Write a piece of code that constructs a two-dimensional array of integers with 5 rows and 10 columns. Fill the array with a multiplication table, so that array element [i][j] contains the value i * j. Use nested for loops to build the array. java Program

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT