Sign Up

Continue with Facebook
Continue with Google
or use

Have an account? Sign In Now

Sign In

Continue with Facebook
Continue with Google
or use

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

Continue with Facebook
Continue with Google
or use

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

Ansfind

Ansfind Logo Ansfind Logo Ansfind Logo Ansfind Logo
Add question

Ansfind Navigation

  • About Us
  • Groups
    • Add group
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Hot Questions
  • Polls
  • Tags
  • Points
  • Users
  • FAQs
  • Help
  • Contact Us
Ramesh RTN
Ramesh RTN
Asked: October 3, 20212021-10-03T21:34:10+05:30 2021-10-03T21:34:10+05:30In: MCQ

Which of the following for loop declaration is not valid?

Which of the following for loop declaration is not valid?

A) for ( int i = 7; i <= 77; i += 7 )

B) for ( int i = 99; i >= 0; i / 9 )

C) for ( int i = 2; i <= 20; i = 2* i )

D) for ( int i = 20; i >= 2; – -i )

javajava interview questionsjava mcq questionsjava question
  • 0
  • 11
  • 1,874
  • Share
    • Share on Facebook
    • Share on Twitter
    • Share on LinkedIn
    • Share on WhatsApp
Answer

    Related Questions

    • Why is java considered a hard programming language?
    • Why does Java have so many undocumented features?
    • Which of the following methods are valid from java.io.file package?

    1 Answer

    • Voted
    • Oldest
    • Recent
    1. Dayana
      2021-10-05T15:02:36+05:30Added an answer on October 5, 2021 at 3:02 pm

      Answer: B) for ( int i = 99; i >= 0; i / 9)

      Explanation: Above question is which is not a valid declaration for loop in given statements so the correct answer is option B.

      Java for loop syntax is:

      for(initialization expression;  test expression; update expression)

      { // code block to be executed }

      Initialization Expression: This expression, we have to initialize the loop counter of some value. Example: int i=1;

      Test Expression: This expression, we have to test the condition. If the condition evaluates to true then, we will execute the body of the loop and go to update expression. Otherwise, we will exit from the for loop. Example: i<10;

      Update Expression: This expression increments/decrements the loop variable by some value, After executing the loop body. Example: i++;

      Given expression option B) for ( int i = 99; i >= 0; i / 9) here 3rd or update expression is i/9 not declared correctly. third expression should be increments/decrements variable. It would not execute, and an exception is thrown, as shown below.

      Exception in thread “main” java.lang.Error: Unresolved compilation problem: Syntax error on token “/”, invalid AssignmentOperator

      Hence the other 3 options are valid and execute. option B) is Not Valid.

       

      • 7
      • Reply
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp
    Leave an answer

    Leave an answer
    Cancel reply

    Browse

    Choose from here the video type.

    Put Video ID here: https://www.youtube.com/watch?v=sdUUx5FdySs Ex: "sdUUx5FdySs".

    Sidebar

    Top Users

    Weboptify

    Weboptify

    • 3,266 Points
    Wish Lay

    Wish Lay

    • 2,310 Points
    Manu Murthy

    Manu Murthy

    • 1,595 Points

    Adv 250x250

    • About Us
    • Home
    • Communities
    • Polls
    • Tags
    • Points
    • Users
    • Help
    • Contact Us
    • Referrals
    • Policies
      • Privacy policy
      • Terms of use
    Revenue

    © 2022 Ansfind. | Designed by Weboptify

    monetization_on category home emoji_events
    search
    help

    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.