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 6822571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:40:45+00:00 2026-05-26T21:40:45+00:00

I’ve been having troubles trying to figure out how to solve a function. I’ve

  • 0

I’ve been having troubles trying to figure out how to solve a function. I’ve been assigned the development of a little programme which tells if a number is “triangular” (a number is triangular when the addition of certain consecutive numbers in the [1,n] interval is n. Following the definition, the number 10 is triangular, because in the [1,10] interval, 1+2+3+4=10).

I’ve coded this so far:

class TriangularNumber{

  boolean numTriangular(int n) {
    boolean triangular = false;
    int i = n;
    while(n>=0 && triangular){
    //UE06 is a class which contains the function "f0", which makes the addition of all the numbers in a determined interval
    UE06 p = new UE06();
      if ((p.f0(1, i))==n)
        triangular = true;
      else
        i=i-1;
    }
    return triangular;
  }

boolean testTriangular = numTriangular(10) == true && 
  numTriangular(7) == false && 
  numTriangular(6) == true;

  public static void main(String[] args){

    TriangularNumber p = new TriangularNumber();
    System.out.println("testTriangular = " + p.testTriangular);
   } 
}

According to those boolean tests I made, the function is wrong. As I see the function, it goes like this:

  1. I state that the input number in the initial state isn’t triangular
    (triangular=false) and i=n (determining the interval [1,i] where the
    function is going to be evaluated
  2. While n is greater or equals 0 and the number isn’t triangular, the
    loop starts
  3. The loop goes like this: if the addition of all the numbers in the
    [1,i] interval is n, the number is triangular, causing the loop to
    end. If that statement is false, i goes from i to (i-1), starting
    the loop again with that particular interval, and so on till the
    addition is n.

I can’t spot the error in my “algorithm”, any advice?

Thanks!

  • 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-26T21:40:46+00:00Added an answer on May 26, 2026 at 9:40 pm

    In your loop the condition should be changed to:

    while(i>=0 && !triangular)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I have a jquery bug and I've been looking for hours now, I can't
I used javascript for loading a picture on my website depending on which small
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I am trying to loop through a bunch of documents I have to put

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.