Complete the loops to print the harshad numbers

Assignment Help JAVA Programming
Reference no: EM131588753

Lab- Loops

Harshad or Niven numbers are positive integers ≥ 1 that are divisible by the sum of their digits. For example, 42 is a Harshad number as 42 is divisible by (4 + 2) without remainder.

Using the code shown below, complete the loops to print the Harshad numbers in the range of 1 to 1000.

public class Harshad {

public static void main(String[] args) { int max = 1000;
for (int i = 1; i < max; i++) {
// Loop to sum the digits of i int j = i, sum = 0;
while ( . . . ) { // Complete the loop condition
// Add logic to compute the sum of the digits
}
// Check if this is a Harshad number
if ( . . . ) { // Complete the if statement System.out.println(i + " is a Harshad number");
}
}
}
}

Hint: the modulus operator can be used to extract single digits.

Reference no: EM131588753

Questions Cloud

Evaluate the approximate costs and benefits of investment : Evaluate the approximate costs and benefits of the investment you identified, explaining how these would affect your spreadsheet projections
Draw free-body diagrams for each element : Determine displacements, bending moments, arid shear forces in the plane frame shown in Figure 4.76. Draw free-body diagrams for each element clearly showing.
Vb coding language to decribe the process : Describe at least three different ways that programs within that system access, store, and manage data. Please include at least one example of a program.
Compute the average cost per unit : Create a spreadsheet listing the number of units you have taken in college so far. The total units take so far is 15 classes. Compute the average cost per unit
Complete the loops to print the harshad numbers : Complete the loops to print the Harshad numbers in the range of 1 to 1000 - public class Harshad
Define a learners license and an operators license : What is the difference between a learner's license and an operator's license
What is the duty of care owed in this circumstance : Over summer you are working with a tourist operator in the Auckland Harbour. What is the duty of care owed in this circumstance? Use case to support your answer
Would you choose the llc as the organizational form : If you were operating your own business, would you choose the LLC as the organizational form for your business?
Explain what happen when you reach court : explain what happen when you reach court, explain how procedure was done

Reviews

Write a Review

JAVA Programming Questions & Answers

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Write a university grading system in java

University grading system maintains number of tables to store, retrieve and manipulate student marks. Write a JAVA program that would simulate a number of cars.

  Wolves and sheep: design a game

This project is designed a game in java. you choose whether you'd like to write a wolf or a sheep agent. Then, you are assigned to either a "sheep" or a "wolf" team.

  Build a graphical user interface for displaying the image

Build a graphical user interface for displaying the image groups (= cluster) in JMJRST. Design and implement using a Swing interface.

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  Input pairs of natural numbers

Java program to input pairs of natural numbers.

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

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