Eric.
Premium
- 8,515
- GTP_Eric
- Ebiggs
Before anyone points it and and tries to derail the thread, yes this is a homework assignment. However, all the code is there, I'm just lost as to what is keeping it from compiling.
The application is to write a method isMultiple that takes in two integers, determines if the second integer is a multiple of the first, and then outputs true or false accordingly. I've spiced it up from just using the console to using JOptionPane for dialog boxes, which wasn't necessary but I need to vary things from the old System.out and Scanner crap. No problem figuring out any of the algorithms or anything like that. Problem is that the method has to be inside of an application, so its not just running the code for that under the main method.
Before I go any deeper, I'll post the code.
And when compiling, I get this error message (compiled in jGRASP):
So I obviously don't know how to declare a method within main. Any help? I played around for quite a while with it and got nothing better than this. I did try ending the main codeblock before I declare isMultiple, but then I have to move all of the variables and pretty much everything that is in main over to isMultiple, which I really don't think is right. And I know its possible to do it this way, somehow.
I'd appreciate any advice!
The application is to write a method isMultiple that takes in two integers, determines if the second integer is a multiple of the first, and then outputs true or false accordingly. I've spiced it up from just using the console to using JOptionPane for dialog boxes, which wasn't necessary but I need to vary things from the old System.out and Scanner crap. No problem figuring out any of the algorithms or anything like that. Problem is that the method has to be inside of an application, so its not just running the code for that under the main method.
Before I go any deeper, I'll post the code.
Code:
//
//
//
//
//
// Java application utilizes JOptionPane for user input
// of two integers, then determines if the second integer
// is a multiple of the first. The result is shown to the
// user in another JOptionPane dialog.
import javax.swing.JOptionPane;
public class Multiples
{
public static void main( String[] args )
{
// declare variables
int firstInt = 0; // first integer input from user
int secondInt = 0; // second integer input from user
String firstNumber = "0"; // value read from JOptionPane
String secondNumber = "0"; // value read from JOptionPane
// JOptionPane prompts user for integers and
// stores them accordingly
firstNumber =
JOptionPane.showInputDialog( "Enter the first integer" );
secondNumber =
JOptionPane.showInputDialog( "Enter the second integer" );
// convert to integers
firstInt = Integer.parseInt ( firstNumber );
secondInt = Integer.parseInt ( secondNumber );
// determination
public static void isMultiple()
{
// messages
String messageTrue = secondInt + " is a multiple of " + firstInt +
"\n" + firstInt + " * " + secondInt + " = " + (secondInt / firstInt);
String messageFalse = secondInt + " is not a multiple of " + firstInt;
if ( secondInt % firstInt == 0 )
{
JOptionPane.showMessageDialog( null, messageTrue );
}
else
{
JOptionPane.showMessageDialog( null, messageFalse );
}
} // end isMultiple
} // end main
} // end class Multiples
Code:
----jGRASP exec: javac -g E:\School\2009-2010 Fall\CSCI 1104\Projects\Chapter 7\6.16 Multiples\Multiples.java
Multiples.java:41: illegal start of expression
public static void isMultiple()
^
Multiples.java:41: illegal start of expression
public static void isMultiple()
^
Multiples.java:41: ';' expected
public static void isMultiple()
^
Multiples.java:41: ';' expected
public static void isMultiple()
^
4 errors
----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.
So I obviously don't know how to declare a method within main. Any help? I played around for quite a while with it and got nothing better than this. I did try ending the main codeblock before I declare isMultiple, but then I have to move all of the variables and pretty much everything that is in main over to isMultiple, which I really don't think is right. And I know its possible to do it this way, somehow.
I'd appreciate any advice!