Results 1 to 4 of 4
  1. #1
    logonin is offline Member
    Join Date
    Nov 2015
    Posts
    8
    Rep Power
    0

    Default 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. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default 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.

  3. #3
    logonin is offline Member
    Join Date
    Nov 2015
    Posts
    8
    Rep Power
    0

    Default 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 05:59 AM.

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default 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.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. problems with outputting to screen
    By EscSequenceAlpha in forum AWT / Swing
    Replies: 2
    Last Post: 05-31-2012, 08:02 PM
  2. Replies: 0
    Last Post: 04-21-2011, 09:21 PM
  3. Help With Outputting Data To A File
    By Prodigial Mouse in forum New To Java
    Replies: 14
    Last Post: 01-24-2011, 09:01 PM
  4. Outputting a * triangle
    By blackbeltsas in forum New To Java
    Replies: 1
    Last Post: 10-17-2010, 12:39 PM
  5. Replies: 6
    Last Post: 06-04-2010, 09:43 PM

Posting Permissions

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