• Post Reply Bookmark Topic Watch Topic
  • New Topic

Simple java coding question?  RSS feed

 
Ken Faulkner
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all.

I have recently started a programming course and as part of that I decided to sign up to a few online resources to enhance
my learning experience.I look forward to growing in knowledge and hopefully some day in the future,being able to give back
by helping other newcomers to programming here on Big Moose Saloon (love the freakin name btw)

My question is probably a simple one but it is 2:25 am here and I can't recall how to go about it .


double num1;
double num2;
double num3;
double sum;
double product;
double average;


System.out.print("Enter num1 -> ");
num1 = EasyIn.getDouble();

System.out.print("Enter num2 -> ");
num2 = EasyIn.getDouble();

System.out.print("Enter num3 -> ");
num3 = EasyIn.getDouble();

sum = num1 + num2 + num3;
System.out.println("sum " + sum);

product = num1 * num2 * num3;
System.out.println("product " + product);


average = (num1 + num2 + num3) / 3;
System.out.println("average " + average);

How do I make the program show me the current sum,product and average after each number is entered??
 
Tushar Goel
Ranch Hand
Posts: 934
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Ken, what problem you are facing..

Also please use code tag
 
Molayo Decker
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
This just a simple code to add and multiple. First i define my variables int num1, int num2 and int num3. i also define my result variable which is going to hold my results as a double.
I guess you wanted to return the results as double.
I use the Scanner java.util because it is handy for a beginner and easy to use. All it does is to capture what you typed when you press enter. But you can use anything you feel comfortable with.
There is a whole lot in the java Documentation.
Finally is display the results with the system.out.println command

 
Campbell Ritchie
Marshal
Posts: 55761
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

I am afraid I shall have to tell you off. Please read this:-
We're all here to learn, so when responding to others, please focus on helping them discover their own solutions, instead of simply providing answers.
It appears on the contents page of this forum. We do not believe that you help people by simply giving them a complete solution. You should allow them to work out the problem for themselves before giving complete solutions.
 
Molayo Decker
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Campbell,
I agree. I am new here. Will try and do that.
 
Campbell Ritchie
Marshal
Posts: 55761
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you: welcome to the Ranch
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!