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

  • Home
  • SEARCH
  • 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 3662096
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T01:22:41+00:00 2026-05-19T01:22:41+00:00

I am practicing how to find and remove dead code. I have the following

  • 0

I am practicing how to find and remove dead code. I have the following code:

              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 ) ; 
        }     

My oppinion on this code: first the if statement can be removed, because it does not effect the execution of the rest of the code. Besides c1%16 is the same as c1%8.

How do I handle the loops?

  • 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-19T01:22:42+00:00Added an answer on May 19, 2026 at 1:22 am

    I would start from the inner code of the loop:
    For example inside the inner if you have

    c1 = c1+c1 ; 
    c3 ++ ; 
    c1 /= 2 ; 
    c3 -= 1 ; 
    

    the first and third line cancel each other .. and the same with the second and fourth. Removing those you get the inner if like this:

    if ( c2 < c3 )
    {
    }
    

    which can be eliminated (also removing the need for c2, c3 vars) thus making the enclosing statement look like this:

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

    If we go a step up and reverse the enclosing if/else we get something like this:

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

    and the empty else can be removed. Now if you another step up you get:

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

    An you remove the if completely since it’s already checked in the while above. Now if you write the complete code you get:

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

    you can remove the first while and the initial add/print altogether because the first do loop will have the same semantics.

    In the end you should obtain something like this:

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

    And if you don’t need to actually print the intermediate values you can obtain the final c1 value via simple mathematics in 1-2 steps :-).

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

Sidebar

Related Questions

I have been practicing DDD for a while now with the 4 distinct layers:
I find myself making repetitive mistakes typing keywords and sentences in my code comments.
I have been practicing TDD and (some) XP for a few years now and
I have been practicing TDD in C# for several years now and recently have
I am beginner.Practicing in C# 3.0. The requirement is i have to design model
I am practicing with PHP and AJAX but I have some problems! I'm trying
I'm practicing PyQt and (Q)threads by making a simple Twitter client. I have two
I've recently joined TopCoder and have been practicing in the Practice Rooms for the
I am practicing SQL, and suddenly I have so many tables. What is a
I'm practicing drawing polyline on the Map. I've adopted Sample code from download here.

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.