• Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses and challenges
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

130
Views
Java 'for loop' variables declared in the parameter list

How do I write a 'for' loop that starts counting from the given 'start' number? Without the first statement in the loop, the code will result in an error. Writing 'start = 0;' starts the counting from 0. Thanks in advance!

enter image description here

enter image description here

11 months ago · Santiago Trujillo
2 answers
Answer question

0

You can leave the initial statement blank and just put a semicolon.

for(; start <= end; start++)
11 months ago · Santiago Trujillo Report

0

Just do:

for(int i = start; i <= end; i++){
    end--;
    System.out.print(start);
}

Although in actuality if you want your code to work you have to do:

for(int i = start; i <= end; i++){
    System.out.print(start);
}
11 months ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post job Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2023 PeakU Inc. All Rights Reserved.