"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?
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!
Re: "Operator / is underfined" problem
Re: "Operator / is underfined" problem
You cant perform integer operations on strings!!