EA Forums - Banner

Java help for a beginner?

Hi I am really stuck right now and I am hoping someone can help me. I need to make a variation of the famous "FizzBuzz" code that counts up to a number the user inputs and prints 11 numbers a line to a message box. I have a program that can do what the assignment asks I just can't get it to go to a message box. Here is my current code
import javax.swing.JOptionPane;
public class CozaLozaNotFinsihed
  public static void main(String[] args)
   int result2=0;
    String n = JOptionPane.showInputDialog("Please input an interger");
     int result = Integer.parseInt(n);
    for (int i=0; i<result; i++){
    String Output = (result2 + " " + i);
 System.out.print(" ");
        if (result2 % 11 == 0)
         if (i % 3 == 0 && i % 5 == 0 && i % 7 == 0) {    
     else if (i % 3 == 0 && i % 5 == 0) {
      } else if (i % 5 == 0 && i % 7 == 0) {
      } else if (i % 5 == 0) {
      } else if (i % 3 == 0) {
        } else if (i % 7 == 0) {
      } else {
        System.out.print(" "+i);

It does what the assignment asks but it gets glitchy when it comes to the output box. It prints two of the same number, not any of the words that it is supposed to replace the numbers with. I think to get to this work I need to somehow save the info to a string or strings and print them in a message box. I already know how to print multiple strings to a message box as demonstrated in this code I made
import javax.swing.JOptionPane;

public class CozaLozaFinishednewtest


  public static void main(String[] args)


    String n = JOptionPane.showInputDialog("Please input something");

    String g = JOptionPane.showInputDialog("Please input something");

    String k = JOptionPane.showInputDialog("Please input something");

    String print= (n + " " + g + " " +  k);

     JOptionPane.showMessageDialog(null, print);



The thing is I have no idea how to do that with my CozaLozaWoza code since I am not trying to combine strings. Plus I somehow need it to still check and replace multiples of certain numbers with words. Also I am not aloud to use StringBuilder. So does anyone have any ideas? I know this not a programming forum but I am total beginner and some of the people on those forums kind of assume newcomers know everything they are talking about. So yeah any help would b greatly appreciated. Thanks :)
This discussion has been closed.

Howdy, Stranger!

It looks like you're new here. Sign in or register to get started.