Java Programming
Write a method named isEven that accepts an integer argument. The method should return true if the argument is even, or false if not. The program’s main method should use a loop to generate a random integer. The number of random integers is provided by a user, who must enter a number greater than 10. The loop should then invoke the isEven method to determine whether each integer is even or odd, display the random number and the result. After the loop has completed, the total number of even and odd integers should be displayed.
import java.util.Random; import java.util.Scanner; public class RandomEvenCheck { public static boolean isEven(int n){ return n%2 == 0; } public static void main(String args[]){ Scanner scanner = new Scanner(System.in); System.out.print("How many random numbers? "); int n = scanner.nextInt(); int evenCount = 0, oddCount = 0; Random random = new Random(); int var; for(int i = 0;i<n;i++){ var = random.nextInt(n); if(isEven(var)) { System.out.println(var + "is even"); evenCount++; } else{ System.out.println(var + "is odd"); oddCount++; } } System.out.println("Number of even numbers generated: "+evenCount); System.out.println("Number of odd numbers generated: "+oddCount); } }
Java Programming Write a method named isEven that accepts an integer argument. The method should return...
python In a program, write a function named roll that accepts an integer argument number_of_throws. The function should generate and return a sorted list of number_of_throws random numbers between 1 and 6. The program should prompt the user to enter a positive integer that is sent to the function, and then print the returned list.
Write a Java program that contains a method named ReadAndFindMax. The argument to this method is the filename (of String type). The method opens the file specified in the method argument filename and then reads integers from it. This file can contain any number of integers. Next, the method finds the maximum of these integers and returns it. The main method must first ask the user to enter the filename; then call ReadAndFindMax method with the entered filename as an...
Programming 5_1: Create a Java class named <YourName>5_1 In this class create a main method, but for now leave it empty. Then write a Java method getAverage which takes an array of integers as it’s argument. The method calculate the average of all the elements in the array, and returns that average. The method should work for an array of integers of any length greater than or equal to one. The method signature is shown below: public static double getAverage(...
Write a function called isEven() that uses the remainder (modulus) operator (%) to determine when an integer is even. The function should take an integer argument called myNumber passed from within the for loop and return true if the integer is even and false otherwise. Your program should determine what numbers are even and odd from 1 to 20 using the isEven() function. Your counter variable in the for loop should be called num.
C++ Programming 1. Write a function (header and body) that accepts an integer as an argument and returns that number squared. 2. Write the code that will fill an integer array named multiples with 10 integers from 5 to 50 that are multiples of five. (This should NOT be in the form of an initialization statement.) 3. Write the code that will display the contents of the integer array named multiples. Recall: the size of the array is 10. 4....
****WRITE A JAVA PROGRAM THAT : Write a method named stretch that accepts an array of integers (that the user inputs) as a parameter and returns a new array twice as large as the original, replacing every integer from the original array with a pair of integers, each half the original. If a number in the original array is odd, then the first number in the new pair should be one higher than the second so that the sum equals...
IN C++ PLEASE Write a class LuckyNumberChecker. Include a constructor that accepts an integer named luckyDivisor Add a virtual method named checkNumber that accept an integer named number and returns a string If the number argument is evenly divisible by the luckyDivisor, return "This number is lucky" otherwise, if the number is odd, return "This number might be lucky" otherwise, return "this number is not lucky" Write a class DoublyLuckyNumberChekcer that extends LuckyNumberChecker Add a constructor that accepts two integers,...
In python programming. Write a recursive function that accepts an integer argument, n. The function should display n lines of asterisks on the screen, with the first line showing 1 asterisk, the second line showing 2 asterisks, up to the nth line which shows n asterisks.
For Python debugExercise12.py is a recursive function that accepts an integer argument, n, and prints the numbers 1 up through n. By debugging these programs, you can gain expertise in program logic in general and the Python programming language in particular. def main(): # Local variable number = 0 # Get number as input from the user. number = int(input('How many numbers to display? ')) # Display the numbers. print_num(number) # The print_num function is a a recursive function #...
Sum of Numbers Problem: Write a method that accepts an integer argument and returns the sum of all the integers from 1 up to the number passed as an argument. For example, if 50 is passed as an argument, the method will return the sum of 1, 2, 3, 4, . . . 50. Use recursion to calculate the sum. Demonstrate the method in a program. The program should be called SumOfNumbers.java.