Results 1 to 4 of 4
- 12-21-2015, 02:35 AM #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) { } } } } }
"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.
- 12-21-2015, 02:49 AM #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 02:54 AM.
If you don't understand my response, don't ignore it, ask a question.
- 12-21-2015, 05:45 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); }
"[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); } } } }
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); } } }
"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 05:59 AM.
- 12-21-2015, 01:39 PM #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)
See the API doc for a description of what the method requires for arguments.
For testing you could use the System.out.println() method.If you don't understand my response, don't ignore it, ask a question.
Similar Threads
-
problems with outputting to screen
By EscSequenceAlpha in forum AWT / SwingReplies: 2Last Post: 05-31-2012, 08:02 PM -
Multiple Entries in sun-ejb-jar.xml or Dynamic annotations for Message Driven Bean?
By shptlucky in forum Enterprise JavaBeans (EJB)Replies: 0Last Post: 04-21-2011, 09:21 PM -
Help With Outputting Data To A File
By Prodigial Mouse in forum New To JavaReplies: 14Last Post: 01-24-2011, 09:01 PM -
Outputting a * triangle
By blackbeltsas in forum New To JavaReplies: 1Last Post: 10-17-2010, 12:39 PM -
java message box, how to not show multiple message box with same title or content
By oohay in forum AWT / SwingReplies: 6Last Post: 06-04-2010, 09:43 PM
Bookmarks