Java Programming (MindTap Course List)
Java Programming (MindTap Course List)
9th Edition
ISBN: 9781337397070
Author: Joyce Farrell
Publisher: Cengage Learning
bartleby

Videos

Expert Solution & Answer
Book Icon
Chapter 6, Problem 5PE

Explanation of Solution

Program:

File name: “Perfect.java

//Import necessary header files

import java.util.*;

//Define a class named Perfect

public class Perfect

{

    //Define main method

    public static void main(String args[])

    {

        //Declare a variable

        int i;

        //Print the message

System.out.println("The perfect numbers in the range 1 to 1000 are:");

        //For loop to print the perfect numbers between 1 and 1000

        for(i = 1; i <= 1000; i++)

        {

            //Declare variables and initialize the value

            int sum = 0, j;

//For loop is executed until the value of j exceeds i

            for(j = 1; j < i; j++)

...

Blurred answer
Students have asked these similar questions
Creating Enumerations In this section, you create two enumerations that hold colors and car model types. You will use them as field types in a Car class and write a demonstration program that shows how the enumerations are used.   1. Open a new file in your text editor, and type the following Color enumeration: enum Color {BLACK, BLUE, GREEN, RED, WHITE, YELLOW};   2. Save the file as Color.java.   3. Open a new file in your text editor, and create the following Model enumeration: enum Model {SEDAN, CONVERTIBLE, MINIVAN};   4. Save the file as Model.java. Next, open a new file in your text editor, and start to define a Car class that holds three fields: a year, a model, and a color.  public class Car {  private int year;  private Model model;  private Color color;   5. Add a constructor for the Car class that accepts parameters that hold the values for year, model, and color as follows:  public Car(int yr, Model m, Color c) {  year = yr;  model = m;  color = c;  }   6. Add a display()…
write an application that reads English-Language phrase and encodes it into morse code. also write an application that reads a phrase in morse code and converts it into the English-Language equivalent . Use one blank between each Morse-code letter and three blanks between each Morse-coded word.
IN JAVA When people enter their telephone numbers into a form they use many different formats. Some examples are: (444) 999-1234 4449991234 444.999.1234 In the PhoneNumbers class below, complete the cleanNumber method. It takes a string and extracts the numeric digits from the string. If there are exactly 10 numeric digits, the number is reformatted: (###) ###-#### and returned. If there are any other number of digits, the string "Error" is returned. Hint: Use the Character.isDigit method to check whether a character is a digit. public class PhoneNumbers{   /**      Cleans a phone number.      @param phoneNumber a phone number that should contain ten digits and possibly other characters      @return the phone number in the form (###) ###-#### or the string "Error" if phoneNumber      does not have ten digits   */   public String cleanNumber(String phoneNumber)   {         // your work here      ...      for (int i = 0; i < ...; i++)      {         char ch = phoneNumber.charAt(i);…
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
  • Text book image
    EBK JAVA PROGRAMMING
    Computer Science
    ISBN:9781337671385
    Author:FARRELL
    Publisher:CENGAGE LEARNING - CONSIGNMENT
    Text book image
    EBK JAVA PROGRAMMING
    Computer Science
    ISBN:9781305480537
    Author:FARRELL
    Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781305480537
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Java random numbers; Author: Bro code;https://www.youtube.com/watch?v=VMZLPl16P5c;License: Standard YouTube License, CC-BY