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);
     Integer.toString(result2);
     
    for (int i=0; i<result; i++){
    Integer.toString(i);
    String Output = (result2 + " " + i);
 System.out.print(" ");
           ++result2;
        if (result2 % 11 == 0)
          System.out.println();
        
         if (i % 3 == 0 && i % 5 == 0 && i % 7 == 0) {    
           System.out.print("CozaLozaWoza");} 
        
     else if (i % 3 == 0 && i % 5 == 0) {
        System.out.print("CozaLoza");
        
      } else if (i % 5 == 0 && i % 7 == 0) {
          System.out.print("LozaWoza");
        
      } else if (i % 5 == 0) {
          System.out.print("Loza");
          
      } else if (i % 3 == 0) {
        System.out.print("Coza");
        
        } else if (i % 7 == 0) {
        System.out.print("Woza");
        
        
        
        
      } else {
        System.out.print(" "+i);
        JOptionPane.showMessageDialog(null,Output);  
  }
}
        
    }
}

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.