• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Simple java coding question?

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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??
 
Ranch Hand
Posts: 954
4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Ken, what problem you are facing..

Also please use code tag
 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Marshal
Posts: 76403
364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Campbell,
I agree. I am new here. Will try and do that.
 
Campbell Ritchie
Marshal
Posts: 76403
364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you: welcome to the Ranch
 
Get out of my mind! Look! A tiny ad!
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic