Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3306540
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:18:02+00:00 2026-05-17T21:18:02+00:00

the last thing I want to minimize today is code that contains while and

  • 0

the last thing I want to minimize today is code that contains while and do-while loops. Here is the original:

class Vereinfache3_edit { 

        public static void main(String [] args) {

           int c1 = Integer.parseInt(args[0]) ;
           int c2 = Integer.parseInt(args[1]) ;
           int c3 = Integer.parseInt(args[2]) ;

/*  1 */           c1 += 7 ; 
/*  2 */           System.out.println( c1 ) ; 

/*  3 */       while (c1 % 8 != 0)
/*  4 */              if ( c1 % 16 == 0 ) ; 
/*  5 */              else
/*  6 */         do 
/*  7 */                 {
/*  8 */                    c1 += 7 ; 
/*  9 */                    System.out.println( c1 ) ; 
/* 10 */                    if ( c2 < c3 )
/* 11 */                       { c1 = c1+c1 ; 
/* 12 */                         c3 ++ ; 
/* 13 */                         c1 /= 2 ; 
/* 14 */                         c3 -= 1 ; 
/* 15 */                       }
/* 16 */                 }
/* 17 */                 while ( c1 % 8 != 0 ) ;

/* 18 */           c1 += 7 ; 
/* 19 */           System.out.println( c1 ) ; 
        }          

}  // end of class Vereinfache3

And here is my minimized version:

class Vereinfache3 { 

        public static void main(String [] args) {

               int c1 = Integer.parseInt(args[0]);
               int c2 = Integer.parseInt(args[1]) ;
               int c3 = Integer.parseInt(args[2]) ;

               do{
                   c1 += 7 ; 
                   System.out.println( c1 ) ;               
               }while (c1 % 8 != 0);

/* 18 */       c1 += 7 ; 
/* 19 */       System.out.println( c1 ) ; 
        }          

}  // end of class Vereinfache3

It generates the same output for me. Do you see any errors or things that can be improved?

Especially this code seems to be tricky:

/*  3 */       while (c1 % 8 != 0)
/*  4 */              if ( c1 % 16 == 0 ) ; 
/*  5 */              else
/*  6 */          do{}

How do I deal with the while? What contains the while loop?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T21:18:02+00:00Added an answer on May 17, 2026 at 9:18 pm

    Your minimized version produces the same result as the original version, different outputs for your original solution and your minimized version are possible only in the case when c1 % 8 != 0 and c1 % 16 == 0,
    this case is impossible since all multiples of 16 are multiples 8 too..

    Removing the unused declarations..is the only improvement I could suggest.
    I do have a solution with less code..Not that it makes things any better…i don’t like too many sysouts in code..:)

        int finalBound = ((c1 + 7) % 8 == 0) ? c1 + 7 : 8 * c1;
        for (; c1 <= finalBound; c1 += 7) {
            System.out.println(c1 + 7);
        }
    

    Hope that helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm about to develop a rich client desktop app. The last thing I want
I have a final question on my piece of code. As a last thing
I did a lot of PHP programming in the last years and one thing
Last year, Scott Guthrie stated You can actually override the raw SQL that LINQ
last time I asked how to populate a data structure here . Now I
Last week we released Omniture's analytics code onto a large volume of web sites
I'm trying to write code that will traverse an undirected, unweighted graph. Essentially, the
I've read several comments here and elsewhere suggesting that Erlang's process dictionary was a
I am writing a shell script to, among other things, determine the last time
Last time I asked about the reverse process , and got some very efficient

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.