stop the user from entering an input after the 10th input

jenna middleton

I'm very new to java and I'm wondering on how to stop the user from entering an input after the 10th. (inputs are separated by space)

sample output would be:

Please type 10 temperatures in Celsius: 30 12 20.5 ..

Temperatures in Celsius: 30.0 12.0 20.5 …

Temperatures in Fahrenheit: 86.0 53.6 68.9 …

Here's my code:

import java.util.Scanner;
public class array {
    public static void main(String args[]) {

        double [] a = new double [10];
        Scanner sc=new Scanner(System.in);

        System.out.print("Please type 10 temperatures in Celsius: ");
        for(int j=0; j<10; j++)
            a[j] = sc.nextDouble();

        System.out.print("Temperatures in Celsius:  ");
        for (int i=0;i<a.length;i++)
            System.out.print(a[i] + " ");

        System.out.print("\nTemperatures in Fahrenheit:  ");
        for (int i = 0; i < a.length; i++) 
            a[i] = a[i]*1.8+32;

            for (int i = 0; i < a.length; i++) {
               System.out.printf("%.1f ", a[i]);
            }

    }
}
Daniel

This is not possible, because input is provided from a terminal/shell, and this terminal usually reads input linewise. You have to do much more low level coding to handle scenarios like these.

Just output an error if the users enters more than 10 values and let him enter them again.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to prevent user from entering zero as an input?

From Dev

Stop a for loop when user is finished entering input in c

From Dev

How to stop reading input from user after a certain char using raw_input() in Python?

From Dev

How to stop reading input from user after a certain char using raw_input() in Python?

From Dev

How to let stop the user from entering only "()" and outputting only "()" after that

From Dev

Stop user from inputing text in input field

From Dev

How to prevent a user from entering negative values in Html input

From Dev

Preventing user from entering negative numbers in input elements with number type

From Dev

Knockoutjs Observable Subscription (loop) - Prevent user from entering wrong input

From Dev

Input box - Prevent user from entering 0 as first digit

From Dev

Knockoutjs Observable Subscription (loop) - Prevent user from entering wrong input

From Dev

trying to make a program that only accepts single digit inputs and then displays after it hits the 10th input

From Dev

How to stop vba after user cancels input box

From Dev

Stop user from entering only spaces in textfield?

From Dev

How to stop waiting for user input?

From Dev

stop at anypoint upon user input?

From Dev

Python: wait for user input, and if no input after 10 minutes, continue with program

From Java

How can I make sure the User can input again after entering something invalid?

From Dev

How can I make sure the User can input again after entering something invalid?

From Dev

Creating a list from user input using stop chars

From Dev

Entering numbers from form input into an array PHP

From Dev

Entering data in a input from an other host

From Dev

How to take any input from the users in capital letters even if the user is entering it in small letters?

From Dev

How can i prevent a user from entering only numbers in an input field

From Dev

Python - input from a user

From Dev

Make something visible on right side after an input is entered from a user

From Dev

Substitute the remaining part of line after pattern matching with input from user

From Dev

How to execute Print statement after getting input from user

From Dev

Execute a command after some time if no input from user

Related Related

  1. 1

    How to prevent user from entering zero as an input?

  2. 2

    Stop a for loop when user is finished entering input in c

  3. 3

    How to stop reading input from user after a certain char using raw_input() in Python?

  4. 4

    How to stop reading input from user after a certain char using raw_input() in Python?

  5. 5

    How to let stop the user from entering only "()" and outputting only "()" after that

  6. 6

    Stop user from inputing text in input field

  7. 7

    How to prevent a user from entering negative values in Html input

  8. 8

    Preventing user from entering negative numbers in input elements with number type

  9. 9

    Knockoutjs Observable Subscription (loop) - Prevent user from entering wrong input

  10. 10

    Input box - Prevent user from entering 0 as first digit

  11. 11

    Knockoutjs Observable Subscription (loop) - Prevent user from entering wrong input

  12. 12

    trying to make a program that only accepts single digit inputs and then displays after it hits the 10th input

  13. 13

    How to stop vba after user cancels input box

  14. 14

    Stop user from entering only spaces in textfield?

  15. 15

    How to stop waiting for user input?

  16. 16

    stop at anypoint upon user input?

  17. 17

    Python: wait for user input, and if no input after 10 minutes, continue with program

  18. 18

    How can I make sure the User can input again after entering something invalid?

  19. 19

    How can I make sure the User can input again after entering something invalid?

  20. 20

    Creating a list from user input using stop chars

  21. 21

    Entering numbers from form input into an array PHP

  22. 22

    Entering data in a input from an other host

  23. 23

    How to take any input from the users in capital letters even if the user is entering it in small letters?

  24. 24

    How can i prevent a user from entering only numbers in an input field

  25. 25

    Python - input from a user

  26. 26

    Make something visible on right side after an input is entered from a user

  27. 27

    Substitute the remaining part of line after pattern matching with input from user

  28. 28

    How to execute Print statement after getting input from user

  29. 29

    Execute a command after some time if no input from user

HotTag

Archive