Hey, I have completed my code for Java and I have to put it in GUI, problem is I dont know a thing about GUI or if my program works correctly with it or not.
Here is my code and what the code does is you type in random numbers (Example 234) and it will tell you what the sum of those digits are (the answer it would give is 9) then it will give you the mod 9 of the answer.
Will this code work with GUI?
import javax.swing.JOptionPane;
public class Sumofdigits
{
public static void main(String[] args)
{
// Set variables
long b;
// Make the GUI
String inputValue = JOptionPane.showInputDialog(null, "Enter digits", "Compute the sum of the digits", JOptionPane.QUESTION_MESSAGE);
long n = Long.parseLong(inputValue);
JOptionPane.showMessageDialog(null,n);
// Compute n % 9
b = n % 9;
}
public static long sumDigits(long n)
{
// Set sum equal to 0
long sum = 0;
// Make a while loop
while(n > 0)
{
// Extract the last digit
sum = sum + n % 10;
// Delete the last digit
n = n / 10;
}
return sum;
}
}
Thank you to anyone that can help me out with this problem.