Results 1 to 4 of 4
- 10-02-2013, 07:08 AM #1
Member
- Join Date
- Oct 2013
- Posts
- 1
- Rep Power
- 0
Help with printing intigers divisible by 10?
Been working on this one for a couple hours, can't seem to figure it out.
My assignment is to prompt the user to enter a range of numbers, then print those numbers that are divisible by 10. Also print an * next to those that are also divisible by 30 as well.
Here's what I have so far:
import java.util.Scanner;
public class DivBy10and30
{
public static void main(String[] args)
{
System.out.println("This program will print numbers divisible by 10 ");
System.out.println("between the lowest and highest values you specify.");
System.out.println("It also places an * next to those divisible by 30.");
Scanner scan = new Scanner(System.in);
int lowest;
int highest;
{
System.out.print("Please enter the lowest value : ");
lowest = scan.nextInt();
System.out.print(" Please enter the highest value : ");
highest = scan.nextInt();
}
lowest = (lowest%=10 && lowest);
lowest = lowest + 10;
lowest++;
System.out.println(lowest);
}
}
If someone can help me out with this one that would be great. An explanation would be great as well. Thank you.
- 10-02-2013, 07:18 AM #2
Re: Help with printing intigers divisible by 10?
Work what out? You need to be more specific about what your problem is. Are you getting errors? Then post the exact error messages. If there is some part of the code that is not working as expected then explain what is happening and what should be happening.
- 10-02-2013, 03:39 PM #3
Senior Member
- Join Date
- Jan 2013
- Location
- Northern Virginia, United States
- Posts
- 6,226
- Rep Power
- 15
Re: Help with printing intigers divisible by 10?
Well, I did notice this.
Java Code:lowest = (lowest%=10 && lowest);
I am not even certain what you are doing here but his won't work (it won't even compile).
Only boolean values or relational statements can be used like this.
This is Java, not Perl.
Regards,
JimThe JavaTM Tutorials | SSCCE | Java Naming Conventions
Poor planning on your part does not constitute an emergency on my part
- 10-02-2013, 04:19 PM #4
Member
- Join Date
- Nov 2012
- Location
- Johannesburg, South Africa
- Posts
- 92
- Rep Power
- 0
Re: Help with printing intigers divisible by 10?
if(aNumber % 10 == 0)
You'll have to learn how to use a modulous operator(%) and you'll have to learn about using if-Statements
if(condition) // condition has to be a boolean variable or boolean expression or simply a boolean literal(true/false)
you can't put ant int as a condition
if(intValue) won't work
Similar Threads
-
Printing
By asai in forum AWT / SwingReplies: 1Last Post: 12-17-2012, 05:59 PM -
Implement Custom Printing Logic & Enhanced Word Documents Printing
By sherazam in forum Java SoftwareReplies: 0Last Post: 12-26-2011, 03:52 PM -
Help with printing an arrayList. printing the first element twice
By kingkongjaffa in forum New To JavaReplies: 9Last Post: 08-19-2011, 12:59 AM -
printing string backwards and printing every other
By droidus in forum New To JavaReplies: 22Last Post: 03-10-2011, 09:17 AM -
Printing Help...
By chiragkini in forum AWT / SwingReplies: 1Last Post: 02-17-2009, 06:07 AM
Bookmarks