• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Programming formulas

 
Atah Tabotnjap
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all

I am very very new to JAVA. I have kniowledge of the various structures of the language, but no experience. I wonder if anyone could give me an idea on the best way to go about programming a formuly that gets certain parameters (of which some are formulas by themslves) as input and gives out a value. Just an idea on how to start will be of help. Thanks a lot.
 
Campbell Ritchie
Sheriff
Pie
Posts: 50168
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try working out a formula which takes an int number as its input and returns an int which is the square of its input. You may get overflow errors if you pass a parameter such that |i|>46340.
The easiest way to get i^2 is i * i.

Se what you can make of that, and good luck with it.

Have you got any books? Have you been through the Java Tutorials? Have you got anybody nearby who can teach you? You will find learning programming very difficult without at least some of those resources.
 
Atah Tabotnjap
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply man. I have taken tutorials and have books, i understand a couple of things, but my problem is putting it together to . I want to start somewhere and then continue learning. YOu know learning to program without a project doesn't really do much. I want to know how i can start programming this formula. Do i need for axample just a class with methods or do i declare classes for each parameter which is itself dependent on some other parameters ?? You know that kind of stuff.
 
Bill Shirley
Ranch Hand
Posts: 457
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
an example:



is this what you're looking for?

disclaimer: done off the top of my head, may not compile


give it a try,
fail (we all do),
post your latest attempt, and where you're having problems,
 
Atah Tabotnjap
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bill. That sounds like a good start for me
 
Campbell Ritchie
Sheriff
Pie
Posts: 50168
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
. . . square . . . return value * 2;


And yes, you will have to create a class to hold those methods. I think both Bill's methods could beneficially be declared static, since neither of them alters the state of any possible object.

And as written, you will have to declare the methods static to get it to compile.
 
Atah Tabotnjap
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ritschie, Bill

sorry to bug you, like i said earlier, i am very new to programming and will be asking very basic questions.

I am trying to write basic code where i can input variable values from a keyboard and get an output. Hot do i write such code that takes input ?

Thnaks
 
Bill Shirley
Ranch Hand
Posts: 457
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java I/O example
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are using JDK 5 or later, you will probably find a Scanner easier to use for input:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic