Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8978301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:34:38+00:00 2026-06-15T19:34:38+00:00

I have written the program however I have two problems : I do not

  • 0

I have written the program however I have two problems :

  1. I do not want the counter i to go from 1 to x because then it would try the divisibility test for every number less than the actual user input. I need it to start i from 2 and go until 12 so that you try the test for 2-12 only.

  2. The divisibility test is correct and it works for every number but that’s not whats asked in the program description. I need to implement the mentioned algorithms for each divisibility test. (which i have researched but am not sure how to do it) this simplified program that i have makes more sense – just a place to start would be helpful

(NOTE: cannot use % modulus operator)

Div by 2 The last digit is even (0,2,4,6,8) Ex: 128 is 129 is not
Div by 3 The sum of the digits is divisible by 3 Ex:381 (3+8+1=12, and 12÷3 = 4) Yes 217 (2+1+7=10, and 10÷3 = 3 1/3) No
Div by 4 The last 2 digits are divisible by 4 Ex: 1312 is (12÷4=3) 7019 is not 5 The last digit is 0 or 5 175 is 809 is not
Div by 6 (Note: You may do six as a separate user-defined function or use 2 and 3’s functions) The number is divisible by both 2 and 3 Ex: 114 (it is even, and 1+1+4=6 and 6÷3 = 2) Yes 308 (it is even, but 3+0+8=11 and 11÷3 = 3 2/3) No

There is more but again – just a place to start or link that has some useful info would be appreciated. Thank you

import java.io.PrintStream;
import java.util.Scanner;

public class rwsFinalExam
{
    public static void main(String [] args)
    {
        Scanner scanner = new Scanner( System.in ); 
                     //allows input from concole
        PrintStream out = System.out;               
                    //assigning System.out to PrintStream

        out.print( "Input a valid whole number: " ); 
                    //ouput directions for end user to enter a whole number

        String input = scanner.next();  //holds end user input
        int number;                     //data type and variable 

        try 
        {
            number = Integer.parseInt(input);   
                  //assinging value to number 
                  //integer.parseInt method converts string to int
        }
        catch (Exception e)
        {
            out.println(input + " is not a valid number");
            return;
        }

        if (number < 0)
        {
            out.println(number + " is not a valid number");
            return;
        }

        printDivisors(number);
    }

    private static void printDivisors(int x)
    {
        PrintStream out = System.out;
        for (int i=1; i<x; i++) 
        {
            if (isDivisibleBy(x, i)) //checking divisibility 
            {
                out.println(x + " is divisible by " + i); 
                     //output when value is divisible 
            }
            else
            {
                out.println(x + " is not divisible by " + i); 
                     //output when value not divisible
            }//end if else
        }//end for
    }//end private static

    private static Boolean isDivisibleBy(int x, int divisor)
    {
        while (x > 0)
        {
            x -= divisor;
            if (x == 0)
            {
                return true;
            }
        }
        return false;
    }//end
}//end class rwsFinalExam
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T19:34:39+00:00Added an answer on June 15, 2026 at 7:34 pm

    The first thing you should do is get the digits in an array.

     private static Boolean isDivisibleBy(int x, int divisor)
    {
        char[]b=String.valueOf(x).toCharArray();
        //Store all your digits as characters
        int[]no= new int[b.length];
        for (int i=0;i<b.length;i++)
           no[i]=Integer.parseInt(String.valueOf(b[i]));
        //Now no contains all your integers as an array 
        if(divisor==2)
               return isDivisibleBy2(no);
        else if(divisor==3)
               return isDivisibleBy3(no);
        else if(divisor==4)
               return isDivisibleBy4(no);
        //...................
        else return false;
    }
    

    Then for each test write a method like so for 2:

    private static Boolean isDivisibleBy2(int[] x){
             int lastDigit=x[x.length-1];
             if(lastDigit==0 || lastDigit==2 || lastDigit==4 || lastDigit==6 || lastDigit==8)
               return true;
            else
               return false;
    }
    

    Anyway you’ll have to write similar code for each test.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written php program and uploaded on server. I want run this program
I have program written in C. It takes 2 arguments username/password and try to
I have written a VB.Net program however there is a bug in one of
I have written a php program that generates rss feeds, however I am having
I have written a program, However I have discovered it has a memory leak
I have a program written in AWT, so I am using Frame (Not JFrame/Swing).
I have written a program using Boost threads. I have allocated two buffers (one
i have written the following program however every time i run it, the for
I have written a simple program using parallel python, and all works well. However,
I have written a program to integrate Facebook user chat in C#, however I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.