Question

26. Select the correct text in the passage. Jamie wrote the following code to find a maximum number of a pair of numbers, but is receiving an error. In which line does his error appear? int a, b, val; final int NUMVALS 10; for (int 1-1; 1 <-NUMVALS; İ + 1) { a (int) (Math.randomO 10 1); b (int) (Math.randomO 10 1); System.out.println(a); System.out.println(b); if (a > b) b-a Select... Select. int a, b, val; final int NUMVALS = 10; for (int 1-1; 1 <: NUMVALS; İ + 1) { a (int) (Math.random0 * 10 + 1); b (int) (Math.random) * 10 +1); System.out.println(a); System.out.println(b); if (a > b)b-a;

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

Answer:-

for(int i=1;i<=NUMBERS;i+1) // here is the mistake

you have to writer the for loop like below to increment the value of i.

for(int i=1;i<=NUMBERS;i++)

Add a comment
Know the answer?
Add Answer to:
26. Select the correct text in the passage. Jamie wrote the following code to find a...
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
  • In class we wrote a method closestPairFast that on an input array of numbers, finds the...

    In class we wrote a method closestPairFast that on an input array of numbers, finds the distance of the closest pair by first sorting the input array and then finding the closest adjacent pair. (See the file ClosestPair1D.java in the Code folder on D2L.) In this problem, you are asked to modify the method so that it returns an integer array consisting of the indices of the closest pair in the original array. If there is a tie, just return...

  • Find the error in the following java code and explain how to correct it (val is...

    Find the error in the following java code and explain how to correct it (val is a variable of type int): switch (val) { case 1: System.out.println ("The number is 1"); case 2: System.out.println ("The number is 2"); default: System.out.println ("The number is not 1 or 2"); break;

  • wrote the code in the discbribtion bar Question 26 CLOS Following code is supposed to ask...

    wrote the code in the discbribtion bar Question 26 CLOS Following code is supposed to ask a user to input a numbe then print the numbers from 0 1 4 0 16 (n-1)2 def my_print(inp) for i in range(inp printi"2) n= int(input(Enter a number: ) my_print(n) The code is not working due to incorect format select the comectly formatted code def my_print(inp): for i in range(inp) printi2) n= int(input(Enter a number ) my_print(n) O def my_print(inp): for i in range(inp)...

  • 1. What is the output? System.out.print(3 + 3 * 3); a. 18 b. 12 c. 9 d. 0 e. 10             2.   What is output by the code below? System.out.print("\\dog\\cat&#...

    1. What is the output? System.out.print(3 + 3 * 3); a. 18 b. 12 c. 9 d. 0 e. 10             2.   What is output by the code below? System.out.print("\\dog\\cat"); a. dog b. dogcat c. \\dog\\cat d. \dog\cat e. catdog\\\\             3.   What is returned by the call     getIt(9) ? public static int getIt(int num){ int ans = 0; if( num >=2 ) {      if( num >= 7)         ans += 2;      else         ans += 3; } ans += 4; return ans; }...

  • The following code is a Java code for insertion sort. I would like this code to...

    The following code is a Java code for insertion sort. I would like this code to be modified by not allowing more than 10 numbers of integer elements (if the user enters 11 or a higher number, an error should appear) and also finding the range of the elements after sorting. /* * Java Program to Implement Insertion Sort */ import java.util.Scanner; /* Class InsertionSort */ public class InsertionSortTwo { /* Insertion Sort function */ public static void sort( int...

  • Question 21 Which of the following expression yields an integer between 0 and 100, inclusive? A....

    Question 21 Which of the following expression yields an integer between 0 and 100, inclusive? A. (int)(Math.random() * 100) B. (int)(Math.random() * 101) C. (int)(Math.random() * 100) + 1 D. (int)(Math.random() * 100 + 1 Question 23 The not equal comparison operator in Java is ________. A. != = B. <> C. ^= D. != Question 24 What is the output of the following fragment? for (int i = 0; i < 15; i++) { if (i % 4 ==...

  • composed the following java code to read a string from a text file but receiving compiling...

    composed the following java code to read a string from a text file but receiving compiling errors. The text file is MyNumData.txt. Included the original java script that generated the output file. Shown also in the required output results after running the java program. I can't seem to search for the string and output the results. Any assistance will be greatly appreciated. import java.io.BufferedReader; import java.io.FileReader; import java.util.ArrayList; public class Main {   public static void main(String[] args) {     System.out.print("Enter the...

  • Please help with this, and leave comments explainging the code you wrote, thank you for your...

    Please help with this, and leave comments explainging the code you wrote, thank you for your help Write a Lottery class that simulates a 6-number lottery (e.g. "Lotto"). The class should have an array of six integers named lotteryNumbers, and another array of six integers named userLotteryPicks. The class' constructor should use the Random class to generate a unique random number in the range of 1 to 60 for each of the 6 elements in the lotteryNumbers array. Thus, there...

  • The following piece of code is intended to find the count of negative numbers in the...

    The following piece of code is intended to find the count of negative numbers in the array. The code compiles correctly but it is giving the wrong answer. There are two logic errors in the code causing the incorrect result Identify the lines of code which are giving the incorrect result, re-write the lines of code with the logic errors corrected and give a brief explanation to why they are giving the incorrect result. i int [] list = {-4,...

  • 12) 8 pts. Find the errors in the following code fragment and correct them. #i nclude...

    12) 8 pts. Find the errors in the following code fragment and correct them. #i nclude <iostream> using namespace std; double fudge (double s) f return s 2.3; int mainO cout >> "Your original estimate" double estimate; cin >> estimate; cout << endl; for (int 1 = 0;1c3;i++); cout << "EStimate' < fudge(estimate) <<endl Hint: There are 4 syntax errors. There is one error that is syntactically correct but causes the output to not be what you would expect. Once...

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