Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Does this code meet the standards set forth?

  1. #1
    Junior Member
    Join Date
    Oct 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Does this code meet the standards set forth?

    Hey guys,

    This is my answer to a homework problem and i have the program working but i want to make sure you agree that it meets the functionality because its worded funky.

    Any input is apprciaited

    Problem: Write a method named multiple that determines, for a pair of integers, whether the second integer is a multiple of the first. The method should take two integer arguments and return true if the second is a multiple of the first and false otherwise. [Hint: Use the remainder operator.] The main () method in the test driver should read two integers, call multiple to determine if one is a multiple of the other, and print a message – i.e. as in:
    The number 4 is a multiple of the number 2
    or
    The number 5 is not a multiple of 2

    There is no need to create two classes – simply the test driver.

     
    import java.util.Scanner; //Allows me get values from users.
     
    public class multiples 
    {
    	public static void main(String[] args)
    	{
    		//Initializes Scanner for use
    		Scanner input=new Scanner(System.in);
     
    		//Declaring the Variables I will use.
    		int FirstNumber;
    		int SecondNumber;
    		boolean isamultiple;
     
    		System.out.println("Please Enter First Integer:  \n");
    		FirstNumber = input.nextInt();
    		System.out.println("\nPlease Enter Second Interger:  \n");
    		SecondNumber=input.nextInt();
    		isamultiple=testmultiple(FirstNumber,SecondNumber);
    		if (isamultiple)
     
    			System.out.printf("\nThe number %s is a multiple of the number %s",FirstNumber, SecondNumber);
    		else
    			System.out.printf("\nThe Number %s is not a multiple of the number %s", FirstNumber,SecondNumber);
    			System.exit(0);		
    	}
     
    	public static boolean testmultiple(int Number1, int Number2)
    	{
    		if (Number1%Number2 == 0)
    			return true;
    		else
    			return false;


  2. #2
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Does this code meet the standards set forth?

    Quote Originally Posted by Java Student View Post
    Write a method named multiple
    You haven't done that.
    whether the second integer is a multiple of the first.
    You have done the opposite.
    Improving the world one idiot at a time!

  3. #3
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: Does this code meet the standards set forth?

    1. Incomplete code.
    You haven't done that.
    He did but with other name testmultiple, so standard is not met here
    They want you to implement multiple, not testmultiple.

  4. #4
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Does this code meet the standards set forth?

    Do you think I'm stupid? The whole point of my post was to highlight the incorrect name.
    Improving the world one idiot at a time!

Similar Threads

  1. describe this program code by code ....
    By izzahmed in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 29th, 2011, 11:03 PM
  2. Standards, cloud computing
    By Loadeed in forum The Cafe
    Replies: 0
    Last Post: June 23rd, 2011, 02:44 AM
  3. Replies: 0
    Last Post: September 2nd, 2009, 08:50 AM