Concept explainers
Challenge exercise Write a method isPrime (int n) that returns true if the parameter n is a prime number, and false if it is not. To implement the method, you can write a while loop that divides n by all numbers between 2 and
Trending nowThis is a popular solution!
Chapter 4 Solutions
Objects First with Java: A Practical Introduction Using BlueJ (6th Edition)
Additional Engineering Textbook Solutions
Starting Out with C++: Early Objects (9th Edition)
Starting Out with C++ from Control Structures to Objects (9th Edition)
SURVEY OF OPERATING SYSTEMS
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
Starting Out With Visual Basic (8th Edition)
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
- Solve TriangleProblem3.java. You may need more than one pair of nested loops.arrow_forwardComplete the convert() method that casts the parameter from a double to an integer and return Note that the main() method prints out the returned value of the convert() method. Ex: If the double value is 19.9, then the output is: 19 Ex: If the double value is 3.1, then the output is: 3 512334.3517088.qx3zqy7 LAB ACTIVITY 1 public class LabProgram { 2 NM & in 3 public static int convert(double d) { /* Type your code here */ 4 5 6 7 } 25.20.1: LAB: Write convert() method to cast double to int 8 public static void main(String[] args) { System.out.println(convert (19.9)); System.out.println(convert(3.1)); 00 00 9 10 11 } 12 } LabProgram.javaarrow_forwardExercise PrintTriangles: Write a method to print each of the following patterns using nested-loops in a class called PrintTriangles. The program shall prompt user for the numRows. The signatures of the methods are: public static void printXxxTriangle(int numRows) // Xxx is the pattern's name 1 1 2 1 1 2 4 2 1 1 2 4 8 4 2 1 1 2 4 8 16 8 4 2 1 1 2 4 8 16 32 16 8 4 2 1 1 2 4 8 16 32 64 32 16 8 4 2 1 1 2 4 8 16 32 64 128 64 32 16 8 4 2 1 (a) PowerOf2Triangle 1 1 1 1 1 1 1 2 1 1 2 1 1 3 3 1 1 3 3 1 1 4 6 4 1 1 4 6 4 1 1 5 10 10 5 1 1 5 10 10 5 1 1 6 15 20 15 6 1 1 6 15…arrow_forward
- HangmanAA.java For this program, you will create the game Hangman. (If you are unsure of how to play Hangman, Google it.) The game will start by asking player 1 for a word or phrase (can be multiple words). Then player 1 will be asked how many missed guesses are allowed by player 2. Once this information is received, player 2 will take over. (Have the program print many blank lines of space so that player 2 can’t see what player 1 entered.) The instructions should be displayed for player 2 as well as the number of misses they’re allowed to make before they lose the game. The screen should also output dashes or underscores to represent each letter of player 1’s secret word/phrase. Player 2 should guess one letter at a time. Case should not matter. Typing x or X should give the same result. If that letter is present in the mystery phrase, then it should be displayed. (It will replace the dash/underscore in that spot. Spaces, punctuation, and all other non-alphabetic characters should…arrow_forwardComplete the convert() method that casts the parameter from a double to an integer and returns the result.Note that the main() method prints out the returned value of the convert() method. Ex: If the double value is 19.9, then the output is: 19 Ex: If the double value is 3.1, then the output is: 3 code: public class LabProgram { public static int convert(double d){ /* Type your code here */ } public static void main(String[] args) { System.out.println(convert(19.9)); System.out.println(convert(3.1)); }}arrow_forwardBuild a simple guessing game where it will continuously ask the user to enter a number between 1 and 10. If the user's guesses matched, the user will score 10 points, and display the score. If the users' guess doesn’t match display the generated number. Also, if the user enters “q” then stop the game. my code till now. Please modify my code so that it works. import randomgame(num)if n=='q': def game(n): n= int(input("Enter a number between 1 and 10 ")) print("You entered:",n)r = random.randint(1,10)print("Random number is: ", r)score=0if n==r:print("You won!")print(" Your score: " ,score+10)else:print("You lost! Try again")arrow_forward
- Part I Write a method that takes two parameters: integer n, char operation. If the given operation parameter is '+', then sum all numbers until n, otherwise multiply all numbers until n. Part II Write a method that prints a menu as given below and asks the user to input a value. If the value given by user is 'r' then repeat the menu. If the value given by user is 'e' then stop the code. [r]epeat menu [e]xit Enter an option: Part III Write a method that takes four integer parameters: æl, y1, x2 and y2. The method calcu- lates the distance between two points which theirs coordinate are given by the parameters. Note: Do not compress your files, submit only java files. Note: Do not forget to justify your answers with comments.arrow_forwardUsing Java enter the CountSentences class that performs this function:Instructs the user to type a number which indicates how many words / sentences will be typed (number that indicatesarray size and it should be bigger than 10 and divisible by 5).Using the for loop ask the user to fill in the string values with words / sentences.Show how many words / sentences have been typed in total and using methodShow which shows as an output the strings from the array that meet the following conditions: • Less than 15% of sentence characters are numbers,• No less than 9 vowels (case insensitive),• The sentence should contain a maximum of 12 words,• The last character of the sentence has to be a number.The methodShow method accepts an array as a parameter and returns also an array which contains all the sentences/strings of which meets the above conditions.arrow_forwardComplete the convert() method that casts the parameter from a double to an integer and returns the res Note that the main() method prints out the returned value of the convert() method. Ex: If the double value is 19.9, then the output is: 19 Ex: If the double value is 3.1, then the output is: 3 512334.3517088.qx3zqy7 LAB ACTIVITY 1 public class LabProgram { INM + ∞ 2 25.20.1: LAB: Write convert() method to cast double to int 3 public static int convert (double d) { /* Type your code here */ 4 5 6 7 } 8 public static void main(String[] args) { 9 System.out.println (convert (19.9)); 10 11 12} } System.out.println(convert(3.1)); LabProgram.javaarrow_forward
- Write a test class that has a method to test how long it takes to count from 1 to 10000 in a loop. You can use the method currentTimeMillis from class System to help with the time measurement.arrow_forwardDetermine whether each statement below is true or false. Assume no index is out of bounds. Write either "true" or "false" on each line. Note: The Math.random() method returns a pseudorandom double type number greater than or equal to 0.0 and less than 1.0. int[] a = new int[6]; int[] b = new int[6]; int[] c = a; c[0] = 3;arrow_forwardWrite a method that takes a RegularPolygon as a parameter, sets its number of sides to a random integer between 10 and 20 inclusive, and sets its side length to a random decimal number greater than or equal to 5 and less than 12. Use Math.random() to generate random numbers. This method must be called randomize() and it must take an RegularPolygon parameter. You can call your method in the program's main method so you can test whether it works, but you must remove or comment out the main method before checking your code for a score. You will also need to make sure you do not remove the import statement "import testing.Math" as this is required to check your code for a score.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education