Results 1 to 4 of 4
  1. #1
    khairozy is offline Member
    Join Date
    Dec 2012
    Posts
    1
    Rep Power
    0

    Default "Operator / is underfined" problem

    Hi,

    I'm working on an assignment question which is as follows:

    One integer is a multiple of another integer if the remainder after dividing the first
    integer by the second is zero. Write a program that tests whether one integer is a
    multiple of a second integer. The programís output could appear as follows:
    Sample Output 1
    A test of whether one integer is a multiple of a second integer.
    Enter the first integer: 25
    Enter the second integer: 5
    25 is a multiple of 5 if the following value is zero: 0

    I typed in the following code:

    import java.util.Scanner;
    public class Integer
    {
    public static void main (String [] args)
    {
    Scanner keyboard = new Scanner (System.in);
    System.out.println ("A test of whether one integer is a multiple of a second integer");
    System.out.println ("Enter the first integer ");
    String integer1 = keyboard.nextLine ();
    integer1 = integer1.trim ();
    System.out.print ("Enter the second integer");
    String integer2 = keyboard.nextLine ();
    integer2 = integer2.trim ();
    int remainder = integer1/integer2;

    System.out.println (integer1 + "is a multiple of " + integer2 + "if the following value is zero: " + integer1/integer2);
    }
    }
    I received the following:
    1 error found:
    File: E:\ICSAP\Integer.java [line: 14]
    Error: The operator / is undefined for the argument type(s) java.lang.String, java.lang.String

    Why can't I use the divide operator?

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    786
    Rep Power
    5

    Default Re: "Operator / is underfined" problem

    integer1 and integer2 are strings!
    Read integers instead of strings, or parse the strings e.g. with Integer.parseInt(...) to an integer!

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default Re: "Operator / is underfined" problem

    Please go through Guide For New Members and BB Code List - Java Programming Forum - Learn Java Programming and edit your post accordingly.,

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    Join Date
    Dec 2012
    Posts
    4
    Rep Power
    0

    Default Re: "Operator / is underfined" problem

    You cant perform integer operations on strings!!

Similar Threads

  1. Replies: 0
    Last Post: 12-07-2012, 08:29 AM
  2. Replies: 2
    Last Post: 11-15-2012, 04:20 PM
  3. "Best" implementation of math operator methods?
    By rgrant222 in forum New To Java
    Replies: 2
    Last Post: 09-01-2010, 07:47 AM
  4. Java, Military Format using "/" and "%" Operator!!
    By sk8rsam77 in forum New To Java
    Replies: 11
    Last Post: 02-26-2010, 03:03 AM
  5. Replies: 1
    Last Post: 10-20-2008, 07:35 AM

Posting Permissions

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