import random x = random.randint (0,5) if x == 5: print (x,' Zero') elif x == 4: print (x, 'One') elif x == 3: print (x,' Two') elif x == 2: print (x,'Three') elif x == 1: print (x, 'Four') else: print (x,'Five')
Q: 6 THE NTWICE PROBLEM Complete the method nTwice. The method has two inputs: a String str and an int…
A: NOTE: - Since the question lacks the name of the programming language, so below code is implemented…
Q: Write a program that reads a sentence and store it in an array of characters. The program also reads…
A: #include<bits/stdc++.h>using namespace std;int main(){ char s[1000]; cout<<"Enter…
Q: Complete the following method, prefix(String s1, String s2), which returns true if s7 is a prefix of…
A: Here is the java code of above problem. See below step for code and output.
Q: 1) Print” i” as long as” i” is less than 6 using while loop.…
A: Lets see the solution.
Q: JavaScript Programming One day, Fred and his N friends were playing a card game in which each player…
A: Required: We have to write a code to maximize the sum which we get on the front cards, keeping in…
Q: What is the probability that in a classroom of x people, at least 2 will be born on the same day of…
A: The solution for the above-given question is given below: As you can see in the output for the given…
Q: Given an input string, complete a helper method that extracts the vowels and returns the string of…
A: there are a few things to do perform tasks: First, we should return the result Removing vowels and…
Q: The Random class generates really random numbers.True or False
A: To be determine: True or False.
Q: Write a while loop that prints userNum divided by 2 (integer division) until reaching 1. Follow each…
A: The following corrections need to be made to the program: In the while loop, logical and…
Q: Write a program that lets the user play the game of Rock, Paper, Scissors against the computer. The…
A: Actually, the code has given below:
Q: Write a program that lets the user play the game of Rock, Paper, Scissors against the computer. The…
A: Actually, the code has given below:
Q: Exercise GradesStatistics (Method): Write a program called GradesStatistics, which reads in n grades…
A: Purpose of the program: This program asks the user to insert grades of multiple subjects into an…
Q: Write a Java method splitName() that takes a string (that contains 1 word or more (space-…
A: Sample Response: //Java codeimport java.util.Scanner; public class splitName{ //splitName method…
Q: A cryptogram is a coded message using alphabet substitution. For example, the letter "A" in the…
A: Here, I am writing a python program for the decoded cryptogram.
Q: t user to enter a string Count the occurrences of digital characters, uppercase letters, and…
A: java code : import java.util.Scanner; class CountCharTypes { public static void main(String[]…
Q: What is the probability that in a classroom of x people, at least 2 will be born on the same day of…
A: Solution: Probability of having at least two people's birthdays on the same day through simulating…
Q: Implement the following two methods:/** Return true if the sum of every two sides is* greater than…
A: Program code: // import the Scanner package import java.util.Scanner; // create class MyTriangle…
Q: Write a method that uses a loop to figure out the factorial (n!). The method will take an integer n…
A: Answer:- Program Approach step: The main purpose of a method that uses a loop call itself again n…
Q: JAVA PROGRAMMING Write a test program that inputs, sorts, outputs Integer and Float. And call the…
A: Answer
Q: Let's play a game of FizzBuzz! It works just like the popular childhood game "PopCorn", but with…
A: Answer the above program are as follows:
Q: U is upward, D is downward, L is left and R is right : Using the methods pickDir() and exractInt()…
A: The program is written in java. MAXLOOPS is set to 20.
Q: Java Palindrome Detector A palindrome is any word, phrase, or sentence that reads the same…
A: Algorithm: Start Declare a string variable. Read a string Call a recursive function to check…
Q: Write a program that compares several Strings using the compareTo() method. You should display the…
A: class Test72 { public static void main(String args[]) { // Example 1 System.out.print("Comparing…
Q: In java language has three different method Write the method xyzMiddle(). * * Given a String str,…
A: Objective: This program works with strings, three methods on strings are executed to check middle…
Q: PYTHON!!! Modify the guessing-game program so that the user thinks of a number that the computer…
A: Declare a variable for the minimum number of guesses. In the else part, take another if else…
Q: Write a method that checks whether two words are anagrams. Two words are anagrams if they contain…
A: #include <bits/stdc++.h>using namespace std; bool areAnagram(string str1, string str2){ int n1…
Q: // for some reason this code isn't working.// import java.util.Scanner; Write a program whose…
A: Answer: Explanation: What was the error in your code so we will see one by one 1. we have change the…
Q: Write 3 ways in java to find the string length without using length method. I am asking without…
A: Required:- Write 3 ways in java to find the string length without using the length method. I am…
Q: Modify the code to display the current date in the MM/DD/YYYYmode. And, display the number of hours,…
A: Required: Modify the code to display the current date in the MM/DD/YYYYmode. And, display the number…
Q: A Newton number is a 4-digit integer number for which the sum of its digits to power 4 is equal to…
A: import java.util.Scanner; import java.lang.Math; public class NewtonNumber { public static void…
Q: public static int mystery(int x, int y) { if (x < 0) { return -mystery(-x, y); } else if (y < 0) {…
A: I have answered the question in step 2.
Q: basic java please Write a method starTheString that accepts a string of any size/length and a…
A: Here, Code instructions are given.
Q: int fun(int x, int y) { if (y == 0) %3%3D return 0; return (x + fun(x, y-1)); int fun2(int a, int b)…
A: To do: Explain the given Program
Q: Modify the guessing-game program so that the user thinks of a number that the computer must guess.…
A: from random import randint import random def computer_guess(num): winlist = ["Hooray, I've got it…
Q: Print numbers 0, 1, 2, ..., userNum as shown, with each number indented by that number of spaces.…
A: Actually, Java is a programming language originally developed by James Gosling at Sun Microsystems…
Q: Write a method with a while loop that computes the sum of first n positive integers
A: Note: As per the guidelines can answer the first three questions. Please re-submit the question…
Q: Rewrite the code using "while Loop" instead of "for Loop". Output must remain the same.
A: import java.util.*;public class main { public static void main(String[] args) {int[] numbers = new…
Q: public static int test(int v{ for(int i= 0; i <a.length; i+ +) if(a[i] = = v) return v; } return -…
A: Answer in step2
Q: please answer correctly Algorithm Running Time package test; import java.util. *; import…
A: Answer arrow_forward Algorithm Running Time package test; import java.util.*; import…
Q: In PYTHON use a Monte Carlo Simulation to write a code that gives the probability that in a…
A: For every play-through, we are re-initializing the frequency table to 0. Because through this we are…
Q: Write a program that lets the user play the game of Rock, Paper, Scissors against the computer. The…
A: Note: Below is the required program in the java language. Program Approach: Importing necessary…
Q: **JAVA LANGUAGE** beginner level import java. util.Arrays; import java.util.Scanner; Suppose that…
A: import java.util.Scanner;class Main{ static double priceIsRight(Scanner s, double price){…
Q: Write a java method that receives a string containing letters of the English alphabet and then…
A: Java is a programming language. It contains extensive libraries (package). It can be used to create…
Q: Given a string, write a method that returns the number of occurrences of substrings "baba" or "mama"…
A: Since no programming language is mentioned, I am using python. Algorithm: Start Implement a method…
Q: void func (__ ---){ *total = *x* *y; a. int *x, int *y, int *total O b. int &x, int &y, int &total O…
A: A function is basically a block of code that is used to do some computation. It has a return type.…
Q: An isolated hydrogen atom emits a photon of x eV. Your task is to find the momentum of photon…
A: Required:- Given the atomic number of atom: 5 and we have to find the energy required to remove the…
Q: Many companies use telephone numbers like 555-GET-FOOD so the number is easier for their customers…
A: Actually, python is a easiest programming language. It has a concise(less) code. It is a dynamically…
Q: 1-Write the pseudocode for this method 2-Flowchart for this method public static void…
A: 1:- pseudocode :- 1-bucketSort(arr[]) 2- initialize max_value = 0; 3- for every element in arr 4-…
Q: import javax.swing.JOptionPane; public class Addition { public static void main( String args[] ) {…
A: you are not calculating the sum in your code. you are just assigning the number to sum every time…
Q: Write a program RandomWalker.java that takes an integer command-line argument n and simulates the…
A: Let assume initially the drone is at (x,y)=(0,0) For the required program we want input from command…
For the following code, match the outcome if x =
The answers I got were wrong
Trending now
This is a popular solution!
Step by step
Solved in 2 steps
- Write a java program that reads in three strings and sorts them alphabetically. You can ask to enter 3 strings in three separate lines. It doesn't have to be one line. (USE IF STATMENTS OR SWITCH STATMENTS, NO LOOPS OR ARRAYS) Ex: Enter three strings: Charlie Able BakerStrings in order: Able Baker CharlieWrite a program that reads a number and finds it is a prime or not. 0. A prime number is a number such that 1 and itself are the only numbers that evenly divide it. For example: 3, 5,7, 11, 13, 17. 2.Write Java program that reads array of integers. Calculate the sum of all integers that cointain at least one digit 4. Write Java program that read array of strings. Print all strings that contain at least three characters 's'.
- JAVA: Write a program that reads an integer and prints how many digits the number has, by checking whether the number is ≥ 10, ≥ 100, and so on. (Assume that all integers are less than ten billion.) If the number is negative, first multiply it with –1.Write a program that reads 10 numbers, finds the largest number, prints it, finds the smallest number, and prints itWrite a program that compares several Strings using the compareTo() method. You should display the Strings and display the integer that compareTo() gives you. You must have five examples which result in a number less than 0, five examples which result in a number greater than 0, and two examples which give you exactly 0. This means you need a total of twelve examples. You may not just flip the Strings around; you must have twelve different examples. Here's an example: System.out.print("Comparing \"axe\" with \"dog\" produces "); int i = "axe".compareTo("dog"); System.out.println(i); System.out.print("Comparing \"applebee's\" with \"apple\" produces "); System.out.println( "applebee's".compareTo("apple") ); Comparing "axe" with "dog" produces -3 Comparing "applebee's" with "apple" produces 5 Make a program that asks for the last name of the user. Depending on their last name, make a statement about how long they have to wait during roll call. You need to use else ifs to make sure…
- Write a simple calculator which supports add subtract multiply and divide. Prompt the user for two numbers and an operation. Use number 1-4 for menu options. If divide is selected and the second number is zero, output an error message. If an invalid menu option is selected, output an error message. If all is well, perform the operation and output the result to one decimal. Please write in Java that results like test case examples. ThanksU is upward, D is downward, L is left and R is right : Using the methods pickDir() and exractInt() as shown below, to write a simple automated game: how long does it take a robot to travel from a left line of a field to the right line? Assume field is 15 units apart (meters, kilometers, it doesn’t matter), and the robot starts on the left line. pickDir(): // return string with random direction and random distance (within maxDist) public static String pickDir (int maxDist) { Random r = new Random(); // random number generator // return direction + distance return ( "" + "LRUD".charAt( r.nextInt(4) ) + (r.nextInt(maxDist) + 1) ); } extractInt(): // returns integer from string, from pos p1 to p2: str = "D1" – extractInt(str,1,1); public static int extractInt (String str, int p1, int p2) { return ( Integer.parseInt( str.substring(p1, p2+1) ) ); } Write the main() method that keeps looping until the robot’s random left…In PYTHON use a Monte Carlo Simulation to write a code that gives the probability that in a classroom of x people, at least 2 will be born on the same day of the year, ignoring leap year? The number of people in the class is given by the user as variable x. Here is the code outline that is needed to answer this question. Please use it in your answer: import mathimport random # create and initialize frequency table:ft = []k = 0while(k < 365) : ft.append(0) k = k+1 # Allow the user to determine class size:print("Please type in how many people are in the class: ")x= int(input()) success = 0 # Simulate:c = 0while(c < 10000) : # Step 1: re-initialize birthday frequency table (it must be re-initialized for each play-through (why?): k = 0 while(k < 365) : ft[k] = 0 k = k+1 # Step 2: randomly get x birthdays and update frequency table: k = 0 while(k < x): # your code goes here ########################## k = k+1 # Step 3: Check to see if this…
- Write a Java program that asks the user to enter a string and counts how many times the letter "s" or "S" appears in the string. Display that number and then display the string that many times. Requirements: Call a method that gets the string from the user. Use recursion to ensure the string has at least 5 characters. Call a method that returns the number of times the letter "s" or "S" appears in the string. This method should use recursion. Call a method that takes the number of times the letter"s" or "S" appeared in the string and display the original string that was obtained from the user that many times using recursion. Call a method that sorts the letters in the string and searches for the letter "m". Display Found or Not Found.Exercise GradesStatistics (Method): Write a program called GradesStatistics, which reads in n grades (of int between 0 and 100, inclusive) and displays the average, minimum, maximum, median and standard deviation. Display the floating-point values upto 2 decimal places. Your output shall look like:Enter the number of students: 4Enter the grade for student 1: 50Enter the grade for student 2: 51Enter the grade for student 3: 56Enter the grade for student 4: 53{50,51,56,53}The average is: 52.50The median is: 52.00The minimum is: 50The maximum is: 56The standard deviation is: 2.29The formula for calculating standard deviation is:Hints:public class GradesStatistics {public static int[] grades; // Declare an int[], to be allocated later.// This array is accessible by all the methods.public static void main(String[] args) {readGrades(); // Read and save the inputs in int[] gradesprintArray(grades);System.out.println("The average is " + average(grades));System.out.println("The median is " +…Write an application that reads an integer value from the user and prints the sum ofall even integers between 2 and the input value, inclusive. Print an error message ifthe input value is less than 2. Use Java. Sample Run Examples: Example 1:the user enters 14Output: Sum: 56Example 2:the user enters 1Output: Error number must be greater than 1