How do I save data and use it next time

I am introducing myself as a beginner in Java.I have just made a program.My idea is to get an output depending on the ranges.So here is the program:
import java.util.Scanner;

class  Vedant
{
    public static void main(String[] args)
        {
            Scanner inputa=new Scanner(System.in);
            int b=inputa.nextInt();
            if(b > 0 && b < 20);
            int a=5;
            {
                System.out.println("Answer ="+a);
            }
            if(b<0)
            {
                System.out.println("Invalid");
        }
}
}

Open in new window


The code is perfect.I had doubts in it which were solved by this site.So what I want to do is get an output as 5 if the input is between 1-20.here is an example what I want to do:Suppose today I input it a number like 7 the answer should be 5.The next day I will input another no. like 10 the input will be 5 too.I want it to save and add the numbers automatically.So the first and second input's answer is 5 so I want the program to add up those two numbers automatically without editing the file everyday.Is there any way?I am just a beginner and don't understand much of it.

Also I want to design a statement like to assign multiple inputs as new scanners.Like Scanner a,b,c=new Scanner(System.in);
Vedant NaikAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

krakatoaCommented:
You can save calculations / user input (anything really), to a File and then read it back in later. Look at the File class and the rest of the .io API.
0
awking00Information Technology SpecialistCommented:
>>The code is perfect<<
Only as long as the input is a negative number or not greater than 19. Any program requiring input should work for any and all input. What happens on the third day when a 4 is entered (after the 10 and 7 from the first two days)? There are a number of ways to accumulate input that might require input from a saved file or an array or new scanner input, or other object. These activities would require new methods for reading a file, or summing an array, or prompting for new input, etc. You would probably also want to have a re-start method and, perhaps a delete or remove method and the like. The question seems to be of an educational nature and, as such, the experts are not allowed to provide specific solutions. Keep trying to make additional progress and will be happy to help with questions or suggestions as your program evolves.
0
CEHJCommented:
The code is perfect.

Far from it - it has a serious bug:

if(b > 0 && b < 20);

Open in new window


That's the end of the statement because it has a semicolon

To answer the bit about saving, you should probably use a simple database once you've got the code working. Using one will be more profitable in the end than reinventing one
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Vedant NaikAuthor Commented:
Yup But how should I get the database file working.Can I get a small example code please?
0
CEHJCommented:
https://docs.oracle.com/javadb/

should get you started
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
krakatoaCommented:
Closed.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.