473,398 Members | 2,525 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Even Division Print Loop

3
I need to write a loop that prints each counting number (integer 1+) that evenly divides into the value in the variable target.

For example, if target is 24, the loop should print:

1
2
3
4
6
8
12
24

I sort of know what i need to start, I just don't know how. Help!
Oct 5 '06 #1
1 2249
r035198x
13,262 8TB
I need to write a loop that prints each counting number (integer 1+) that evenly divides into the value in the variable target.

For example, if target is 24, the loop should print:

1
2
3
4
6
8
12
24

I sort of know what i need to start, I just don't know how. Help!
Please modify this so that it takes the integer a as input from the user

Expand|Select|Wrap|Line Numbers
  1. class Factors {
  2.     public static void main(String arg[]) {
  3.         int a = 24;
  4.         for(int i = 1;i < a; i++) {
  5.             if(a%i == 0) {
  6.                 System.out.println (i);
  7.             }
  8.         }
  9.     }
  10. }
Oct 6 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: Tim Rowe | last post by:
If I do from __future__ import division then eval(1/2) gives me 0.5 as expected. But if I do print input("enter a sum: ") and enter 1/2 as the sum I get 0 as if I hadn't done the import. I thought...
5
by: Milan | last post by:
a program: a=10 b=5 print a/b and its result: 0. If you run the program, you see always a sero (0), but 10/5 is 2. Who can help me?
6
by: Artemisio | last post by:
I am a non programmer who just started with Python. So far I love it. I would appreciate if you could help me fix this error I get taking this exercise: count= 0 sum= 0.0 number= 1 print...
9
by: Marcin | last post by:
How I can make division of two numbers placed in arrays, example: short int a = {2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2}; short int b =...
8
by: nineteen | last post by:
for example: 16/5: 3 -------- 5)16 15 -------- 1 the user input the dividend and divisor,the program should display the upright formula like the example. and , the program must use recursive...
94
by: krypto.wizard | last post by:
Last month I appeared for an interview with EA sports and they asked me this question. How would you divide a number by 7 without using division operator ? I did by doing a subtraction and...
1
by: youjay | last post by:
I've been out of perl for a while, so I am starting from scratch. I have a small applet which scans a set of directories, getting information from some files in each one, and displaying selected...
3
by: GiftX | last post by:
Good morning members. I am using VB6 to generate a spreadsheet. My module is working okay but one of my objectives is to print an underline after writing each record in the spreadsheet, just to show...
7
by: Thomascountz | last post by:
I'm completely new to python, I just started about 3 days ago. I've requested some books from my library on python, so I hope I'm headed in the right direction. I hate to ask this because I'm sure...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.