CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 2 of 2

Thread: Help, the program doesn't run even though it should...?

  1. #1
    Join Date
    Oct 2014

    Help, the program doesn't run even though it should...?

    Hey. I am a student trying to learn programming on my own, getting help from online sources and people like you. I found an exercise online to create a small program . I have this code that I have done so far:

    import java.util.Scanner;
    public class Test {
    	public static void main(String args[]) {
        Scanner sc = new Scanner(;
        long a = sc.nextLong(); long b = sc.nextLong();
        long count = 0; // counter
        for (long c = a; c <= b; c++) {
            if (c % 2 == 0 || c % 3 == 0 || c % 5 == 0) {
    The program should read the numbers a and b and list how many numbers between a and b are divisible by either 2, 3 or 5.

    If the user types the number 5 and then 8.... it would look at all the numbers in between - 5,6,7,8 and check if any of them are divasable by either 2,3 or 5. And since the numbers 5,6,8 are it would return the number 3 to the user....

    Now the problem is that this program only works for small numbers, but when I try to input numbers such as 123456789012345678 and 876543210987654321... it doesn't run at all.

    So there needs to be a quicker way on how the program checks the numbers divisibility instead of checking each one. Here is where I am lost. How to fix the program that it will read bigger numbers such as a=123456789012345678 b=876543210987654321

    There must be a quicker way ...something that can modify the code so it finishes in the matter of seconds not hours. Something that will fasten the process of checking if the numbers are dividable...

    Could you please help me with that? Because I am completely lost on what to do. Thank you for your help in advance !

  2. #2
    Join Date
    Jun 1999
    Eastern Florida

    Re: Help, the program doesn't run even though it should...?


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)