Write a progra whether a number is prime

Assignment Help Programming Languages
Reference no: EM131274268

6.1 (Math: pentagonal numbers) A pentagonal number is defined as n(3n-1)/2 for n = 1, 2, . . ., and so on. Therefore, the first few numbers are 1, 5, 12, 22, . . . . Write a method with the following header that returns a pentagonal number:

public static int getPentagonalNumber(int n) Write a test program that uses this method to display the first 100 pentagonal numbers with 10 numbers on each line.

6.2 (Sum the digits in an integer) Write a method that computes the sum of the digits in an integer. Use the following method header:

public static int sumDigits(long n) For example, sumDigits(234) returns 9(2 + 3 + 4). (Hint: Use the % operator to extract digits, and the / operator to remove the extracted digit. For instance, to extract 4 from 234, use 234 % 10 (= 4). To remove 4 from 234, use 234 / 10 (= 23). Use a loop to repeatedly extract and remove the digit until all the digits are extracted. Write a test program that prompts the user to enter an integer and displays the sum of all its digits.

6.3 (Palindrome integer) Write the methods with the following headers // Return the reversal of an integer, i.e., reverse(456) returns 654 public static int reverse(int number)

// Return true if number is a palindrome public static boolean isPalindrome(int number) Use the reverse method to implement isPalindrome. A number is a palindrome if its reversal is the same as itself. Write a test program that prompts the user to enter an integer and reports whether the integer is a palindrome.

6.6 (Display patterns) Write a method to display a pattern as follows:
    1
   2 1
 3 2 1
... n n-1 ..3 2 1

The method header is

public static void displayPattern(int n).

6.10 Write a progra whether a number isPrime(int number) method for testing whether a number is prime. Use this method to find the number of prime numbers less than 10000.

Reference no: EM131274268

Questions Cloud

What is the product of the numbers : Three distinct prime numbers, less than 10 are taken and all the numbers that can be formed by arranging all the digits are taken. Now, difference between the largest and the smallest number formed is equal to 495. It is also given that sum of the di..
Program that plays a commercial video continuously : Determine the type of loop that you would use in your program in order to make the video play continuously. Provide a rationale for your chosen type of loop.
Prepare a draft annotated bibliography : Prepare a draft annotated bibliography. Select a topic, preferably one of your topic interest areas you may pursue for your dissertation. Select 10 articles for the bibliography. The bibliography must have 10 entries critically analyzed, to includ..
Design and code a program including the given classes : Design and code a program including the following classes, as well as a client class to test all the methods coded: A Passenger class, encapsulating a passenger.
Write a progra whether a number is prime : Write a progra whether a number isPrime(int number) method for testing whether a number is prime. Use this method to find the number of prime numbers less than 10000.
Interface for interaction with the operating system : As explained in the textbook, UNIX / Linux initially only provided a command line interface for interaction with the operating system (OS). The introduction of a Graphical User Interface (GUI) to UNIX / Linux OS makes it easier to administer a Lin..
Design a program that asks the user to enter the amount : Design a program that asks the user to enter the amount that he or she has budgeted for a month. Use labels to list expediencies and text boxes to hold the expense (such as housing, entertainment, fuel, power, misc, etc).
Rewrite the given topic in the english language : HMGT 310 - Rewrite the given topic-A growing pol of patients is unable to read and write in the English language. Language is a barrier to effective care delivery as well as patient compliance.
Positive integer n such that the polynomial : For every positive integer b, show that there exists a positive integer n such that the polynomial x^2 - 1 ∈ (Z/nZ)[x] has at least b roots.

Reviews

Write a Review

Programming Languages Questions & Answers

  Sketch state diagram for machine using sw

Sketch the State Diagram for machine using any SW (i.e. MS Visio).: Print out your VHDL Code and Simulation waveforms for you design 3 Points: Print out your VHDL Code for your self-checking Test Bench

  Create a application using the mvc architecture

create a application using the MVC architecture. No scripting elements are allowed in JSP pages.

  Write a haskell program to calculates a balanced partition

Write a program in Haskell which calculates a balanced partition of N items where each item has a value between 0 and K such that the difference b/w the sum of the values of first partition,

  Different class maintain programming programs are organized

It allows different classes to maintain programming so that programs are kept more organized. Object orientation also allows a programmer to use the same objects in different programs. Response?

  Calculates the total number of votes received by a candidate

Calculates the total number of votes received by a candidate - the function updateVotesByRegion (of the class candidateType) updates only the number of votes for a particular region.

  Write a little man program that adds a column of input value

Write a Little Man program that adds a column of input values and produces the sum as output. An input value of zero will indicate the last value in the input stream of input values.

  Design the software architecture of a web auctioning site

Design the software architecture of a Web auctioning site and design a database for storing information about users, items, auctions and bids.

  Design psuedocode program to calculate amount

Design a psuedocode program that calculates the amount of money a person would earn over a period of time if his or her salary is one penny the first day, two pennies the second day.

  Program to calculate sum of squares using for loop

Given int variables k and total that have already been declared, use for loop to calculate sum of squares of first 50 counting numbers, and store this value in total.

  Write application to create-print random phone number

Write the application which creates and prints random phone number of form xxx-xxx-xxxx. Include dashes in the output. Do not let first three digits to contain 8 or 9.

  Write a program to find solutions to the n-queens puzzle

Write a program to find solutions to the n-queens puzzle for various valuesof n. To be specific, test your program for n =4 and n =8.

  Create program which lists total points scored

Create program which lists total points scored for each of 30 classrooms. Include invalid input check if a proper room number is not entered.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd