# Thread: Outputting multiple things into one message box?

1. Member
Join Date
Nov 2015
Posts
8
Rep Power
0

## Outputting multiple things into one message box?

Hi I have to make a variation of the famous "FizzBuzz" code where it replaces multiples of 3 with "coza" multiples of 5 with "loza" and so on. I also have to output it through a message box. This is what is giving me trouble. I have tried so many different things but no matter what I can't figure out how to get this to work. Here is my current code
Java Code:
```import javax.swing.JOptionPane;
public class CozaLozanewmethod
{
public static void main(String[] args)
{
int a = 0;
int b = 0;
int c = 0;
int d = 0;
int e = 0;
int f = 0;
int g = 0;
String A = ("CozaLozaWoza");
String B =("CozaLoza");
String C =("LozaWoza");
String D =("Loza");
String E =("Coza");
String F =("Woza");

int result2=0;
String n = JOptionPane.showInputDialog("Please input an interger");
int result = Integer.parseInt(n);

for (a=0; a <= result; a++){
for ( b=0; b<result; b++){
for ( c=0; c<result; c++){
for ( d=0; d<result; d++){
for ( e=0; e<result; e++){
for ( f=0; f<result; f++){
for ( g=0; g<result; g++){

System.out.print(" ");
++result2;
if (result2 % 11 == 0)
System.out.println();

if (a % 3 == 0 && a % 5 == 0 && a % 7 == 0) {

}else if (b % 3 == 0 && b % 5 == 0) {

} else if (c % 5 == 0 && c % 7 == 0) {

} else if (d % 5 == 0) {

} else if (e % 3 == 0) {

} else if (f % 7 == 0) {

}
}

}
}
}```
I am not sure what I need to put after the "if then" statements so it knows to display the string at that time. Also the code I currently have wont even compile. I get the following errors on line 72

"Error: Syntax error on tokens, ConstructorHeaderName expected instead

Error: Syntax error on token "showMessageDialog", invalid AnnotationName

Error: Syntax error on token ",", ? expected"

So please forgive me for asking so many questions but I am very confused right now.

2. ## Re: Outputting multiple things into one message box?

The alignment of the { and }s needs to be fixed. When they are here and there like in the above code, the code is very hard to read and understand.

What is the purpose of all those empty if statements?
I've never seen for statements nested that deeply. If result were 3 then the inner loop would be executed 3*3*3*3*3*3*3 times

The posted error messages are missing the source line numbers where the errors occur.
The message should show the source with a ^ under the location of the error.
Here is a sample from the javac compiler:
Java Code:
```TestSorts.java:138: cannot find symbol
symbol  : variable var
location: class TestSorts
var = 2;
^```
Last edited by Norm; 12-21-2015 at 01:54 AM.

3. Member
Join Date
Nov 2015
Posts
8
Rep Power
0

## Re: Outputting multiple things into one message box?

Sorry about that for some reason I only copied and pasted a part of my code. Here is my entire code
Java Code:
```import javax.swing.JOptionPane;
public class CozaLozanewmethod
{
public static void main(String[] args)
{
int a = 0;
int b = 0;
int c = 0;
int d = 0;
int e = 0;
int f = 0;
int g = 0;
String A = ("CozaLozaWoza");
String B =("CozaLoza");
String C =("LozaWoza");
String D =("Loza");
String E =("Coza");
String F =("Woza");

int result2=0;
String n = JOptionPane.showInputDialog("Please input an interger");
int result = Integer.parseInt(n);

for (a=0; a <= result; a++){
for ( b=0; b<=result; b++){
for ( c=0; c<=result; c++){
for ( d=0; d<=result; d++){
for ( e=0; e<=result; e++){
for ( f=0; f<=result; f++){
for ( g=0; g<=result; g++){

System.out.print(" ");
++result2;
if (result2 % 11 == 0)
System.out.println();

if (a % 3 == 0 && a % 5 == 0 && a % 7 == 0) {

}else if (b % 3 == 0 && b % 5 == 0) {

} else if (c % 5 == 0 && c % 7 == 0) {

} else if (d % 5 == 0) {

} else if (e % 3 == 0) {

} else if (f % 7 == 0) {

}
}

}
}
}
}
}

}

}
JOptionPane.showMessageDialog(null, A + B + C + D + E + F);
}```
The errors I am getting are

"[line: 72]
Error: Syntax error on tokens, ConstructorHeaderName expected instead

[line: 72]
Error: Syntax error on token "showMessageDialog", invalid AnnotationName

[line: 72]
Error: Syntax error on token ",", ? expected"

Also my code is very confusing so I decided to start over with printing it to the console. So if my first code is to confusing to help solve then can you tell me how to get the desired result with my new code?
Java Code:
```import javax.swing.JOptionPane;

public class CozaLozaFourm2
{
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++){
Integer.toString(i);
Integer.toString(result2);

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 % 3 == 0 && i % 7 == 0){
System.out.print("CozaWoza");

} 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);
}
}
}
}```
Thanks in advanced :)

EDIT- Here is something new I am experimenting with
Java Code:
```import javax.swing.JOptionPane;

public class CozaLozaFourm3
{
public static void main( String[] args )
{
int result2=0;
String n = JOptionPane.showInputDialog( "Please input an interger" );
int result = Integer.parseInt( n );

String s = " ";

for (int i=0; i<result; i++){
Integer.toString(i);
Integer.toString(result2);

System.out.print(" ");
++result2;
if (result2 % 11 == 0)
System.out.println();

if (i % 3 == 0 && i % 5 == 0 && i % 7 == 0) {
s += "Loza";
}
JOptionPane.showMessageDialog(s);
}
}
}```
I get the following error on line 25 that says

"Error: The method showMessageDialog(java.awt.Component, java.lang.Object) in the type javax.swing.JOptionPane is not applicable for the arguments (java.lang.String)"
So yeah I am not even sure if what I am doing on this one is correct just thought I would put it out there.
Last edited by logonin; 12-21-2015 at 04:59 AM.

4. ## Re: Outputting multiple things into one message box?

Error: The method showMessageDialog(java.awt.Component, java.lang.Object) in the type javax.swing.JOptionPane is not applicable for the arguments (java.lang.String)
The compiler can not find a definition for the showMessageDialog method that takes just a String as argument. It wants a Component and Object as args for the method. The Component can be null and the Object can be a String.
See the API doc for a description of what the method requires for arguments.

For testing you could use the System.out.println() method.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•