Question

STEP 1: Type (do not copy and paste) Program 1 into a program and Program 1: import java.util.Scanner; public class Overflow2

Describe the results of above program run in step 1? What happens if you type 3 for the first prompt? What happens if you t

What happens it you type 12 for the first prompt? What happens if you type 20 for the first prompt? What happens if you t

secure cis1.towson.edu/cyber4all/modules/nanomodules/Buffer Overflow-CS1_Java.html What happens if you type 10 for the first

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

This program is asking to enter number of elements in first prompt and in for loop the numbers are being stored fom the entered number to 1 in reverse suppose we enter 3 in first prompt then array will store 3,2,1. and in second prompt we have to enter the value we want to retrieve from array .

If i type 3 for first prompt compiler asks me to enter size of array and in next prompt which value i want to retrieve from array.

If i type 7 for first prompt compiler asks me to enter size of array and in next prompt which value i want to retrieve from array.

If i type 12 for first prompt i got exception  ArrayIndexOutOfBoundException as size of array is fixed by 10 .

If i type 20 for first prompt i got exception  ArrayIndexOutOfBoundException as size of array is fixed by 10 .

If i type 3 for first prompt compiler will ask me size of array and in next prompt which value i want to retrieve from array.

When i type 10 for first prompt and 3 for second prompt i got 7 as output.

When i type 10 for first prompt and 7 for second prompt i got 3 as output.

When i type 10 for first prompt and 12 for second prompt i got an exception ArrayIndexOutOfBoundException.

When i type 10 for first prompt and 20 for second prompt i got an exception ArrayIndexOutOfBoundException.

Add a comment
Know the answer?
Add Answer to:
STEP 1: Type (do not copy and paste) Program 1 into a program and Program 1:...
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
  • So this is all I have done right now. Next steps: 1. Create a method called "printArray" which wo...

    So this is all I have done right now. Next steps: 1. Create a method called "printArray" which would put the code : for(int i = 0; i < myArray.length; i++) System.out.println(myArray[i]); at the bottom of that screen and put it into a method and then call it. 2. Create another method thats going to count all the numbers that are evenly divisible by 10 and call the method whatever you like. * Just make sure to return, pass at...

  • Step 4: Add code that discards any extra entries at the propmt that asks if you...

    Step 4: Add code that discards any extra entries at the propmt that asks if you want to enter another score. Notes from professor: For Step 4, add a loop that will validate the response for the prompt question:       "Enter another test score? (y/n): " This loop must only accept the single letters of ‘y’ or ‘n’ (upper case is okay). I suggest that you put this loop inside the loop that already determines if the program should collect...

  • write a program which include a class containing an array of words (strings).The program will search...

    write a program which include a class containing an array of words (strings).The program will search the array for a specific word. if it finds the word:it will return a true value.if the array does not contain the word. it will return a false value. enhancements: make the array off words dynamic, so that the use is prompter to enter the list of words. make the word searcher for dynamic, so that a different word can be searched for each...

  • Hi I need help with a java program that I need to create a Airline Reservation...

    Hi I need help with a java program that I need to create a Airline Reservation System I already finish it but it doesnt work can someone please help me I would be delighted it doesnt show the available seats when running the program and I need it to run until someone says no for booking a seat and if they want to cancel a seat it should ask the user to cancel a seat or continue booking also it...

  • Java Test 1 Name 1) A Java program is best classified as arsge D) pnocesorE) aa...

    Java Test 1 Name 1) A Java program is best classified as arsge D) pnocesorE) aa 2) 6 bits can be used to represent 3) Binary numbers are composed entirely of ? 4) Define the main method for a Java program 5) Give 2 examples of a legal Java identifier? distinct items or values? 6) A unique aspect of Java that allows code compiled on one machine to be executed on a machine of a different hardware platform is Java's...

  • You will need to think about problem solving. There are several multi-step activities. Design, compile and...

    You will need to think about problem solving. There are several multi-step activities. Design, compile and run a single Java program, StringEx.java, to accomplish all of the following tasks. Add one part at a time and test before trying the next one. The program can just include a main method, or it is neater to split things into separate methods (all static void, with names like showLength, sentenceType, lastFirst1, lastFirst), and have main call all the ones you have written...

  • Which of the following are valid array declarations? a. int[] array- new int[10]; b. double [array...

    Which of the following are valid array declarations? a. int[] array- new int[10]; b. double [array double[10]; c. charl charArray "Computer Science"; None of the above Analyze the following code: class Test public static void main(Stringl] args) System.out.println(xMethod(10); public static int xMethod(int n) System.out.println("int"); return n; public static long xMethod(long n) System.out.,println("long"); return n The program displays int followed by 10 The program displays long followed by 10. The program does not compile. None of the above. tions 3-4 are...

  • With a Scanner object created as follows, what method do you use to read an int...

    With a Scanner object created as follows, what method do you use to read an int value? Scanner input = new Scanner(System.in); A. input.int(); B. input.nextInt(); C. input.integer(); D. input.nextInteger(); What is the output of the following code? x = 0; if (x > 0) System.out.println("x is greater than 0"); else if (x < 0) System.out.println("x is less than 0"); else System.out.println("x equals 0"); A. x is greater than 0 B. x is less than 0 C. x equals 0...

  • I have the following java-program, that creates a random walk starting at (0,0) and continuing until...

    I have the following java-program, that creates a random walk starting at (0,0) and continuing until x or y is greater than abs(n). First: I get an error, when I try closing the Scanner by inserting "reader.close(); " in line 28. It says "Unreachable code". How can I fix that? Second: Is it possible to create a different colour for the StdDraw.point when it reaches a point on one of the edges "n+1" or "n-1" ? 1 import java.util.*; 3...

  • Exercise 1): take the program “InteractiveCounting” (attached). Your task is to change the implementation of both...

    Exercise 1): take the program “InteractiveCounting” (attached). Your task is to change the implementation of both the “ReadInput” and the “Count” classes. Currently these classes extends Thread. You should now use the Runnable interface to implement the thread. The output of the program should not change. I have also attached the class ThreadType2 to give you a working example on how to implement a thread using the Runnable interfacethe program is here package threadExamples; import java.util.Scanner; public class InteractiveCounting {...

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