JavaScript How to not repeat validation in java javascript repeat validation

I'm writing a program that calculates the price of painting rooms in a house. The program asks the user a couple of questions and the user must input certain answers regarding the topic. The program must also implement validation's where 0 and negative numbers are not accepted:

  Scanner keyboard = new Scanner(System.in);

  System.out.println("Number of rooms to be painted?");
  noRooms = keyboard.nextDouble();  

  while (noRooms <= 0) {
    System.out.println("Invalid Input for the number of rooms. Please enter in the appropriate number:");
    noRooms = keyboard.nextDouble();    

  System.out.println("Number of sqaure feet of wall space in each room?");
  wallSpace = keyboard.nextDouble();

  while (wallSpace <= 0) {
    System.out.println("Invalid Input for the number of square feet of wall space. Please enter in the appropriate number:");
    wallSpace = keyboard.nextDouble();

My validation is correct however I have been informed that I must NOT repeat the validations for each input and create only one validation, place it in a method and apply it to each input.

public static void validation(Scanner keyboard, double noRooms, double wallSpace) {    
 while (noRooms <= 0 || wallSpace <= 0) {
   System.out.println("Invalid Input: Please enter in the appropriate number:");
   noRooms , wallSpace = keyboard.nextDouble();
     }
} 

I understand the code above is incorrect and what I must do is implement the method, that combines all the input values, and apply it to the one validation. Any suggestions?

--UPDATE--

So I got the idea of creating the validation like so:

private static double validation(Scanner keyboard) {
double v = keyboard.nextDouble();
  while (v <= 0) {
    System.out.println("Invalid Input: Please enter in the appropriate number:");
}
return v;
}

And to call it within the input like:

System.out.println("Number of rooms to be painted:");
noRoom= keyboard.nextDouble();
noRoom= validation(keyboard);

No errors appear but the program doesn't do anything when I input either the 'correct' or 'incorrect' data. Is there another way to call the method?

Answer:1

as stated in the name, i have a menu with links, and i have a list of sections which i want to show/hide on the click of the menu. What i want here is to be dynamic in a sense that if i add more menus ...

as stated in the name, i have a menu with links, and i have a list of sections which i want to show/hide on the click of the menu. What i want here is to be dynamic in a sense that if i add more menus ...

  1. show content only on mobile
  2. show content only on homepage wordpress
  3. show content only from this computer
  4. wordpress show content only to logged in users
  5. tar show content only
  6. curl show content only
  7. wordpress show content only if logged in
  8. php show content only if logged in
  9. chrome show content only
  10. show my cloud-only content from onedrive
  11. show hide content css only
  12. sharepoint show page content only
  13. how to show only content in excel
  14. ie show secure content only
  15. show content only

I'm using the 500px API module with Node.js and I'm trying to get photos of a specific user. I'm facing issue with function, callback and scope... I've this code : api500px.photos.getByUsername ('...

I'm using the 500px API module with Node.js and I'm trying to get photos of a specific user. I'm facing issue with function, callback and scope... I've this code : api500px.photos.getByUsername ('...

  1. return data callback function
  2. return data callback
  3. return data callback javascript
  4. return data from callback node js
  5. return data from callback function javascript
  6. return data from callback js
  7. return data ajax callback
  8. nodejs return data callback
  9. node return data from callback
  10. python return data from callback
  11. matlab return data from callback

I have a php file on my server to upload file. I tried to upload using that file directly and it was success. Then I wrote a simple phantomjs script, run it on ubuntu with phantomjs version 2.1.1 but ...

I have a php file on my server to upload file. I tried to upload using that file directly and it was success. Then I wrote a simple phantomjs script, run it on ubuntu with phantomjs version 2.1.1 but ...

  1. canvas
  2. canada
  3. cancelled
  4. canceled vs cancelled
  5. cancun
  6. canada goose
  7. cane corso
  8. canes
  9. canadian prime minister
  10. cancun flights
  11. canker sore
  12. candy
  13. cancer
  14. canon
  15. canvas prints
  16. cancer sign
  17. candace owens
  18. canada news
  19. candytopia
  20. canlis

I have an AJAX setup in php to return and dispaly some data from DB: $("#sub_shops").click(function(){ var range_start = $("#start_shops").val(); var range_end ...

I have an AJAX setup in php to return and dispaly some data from DB: $("#sub_shops").click(function(){ var range_start = $("#start_shops").val(); var range_end ...