1

My goal is to have the user be prompted for multiple separate inputs that would store the data in a manner that I could then manipulate.

For example:

Question:
What is your username?
What is your name?
Input:
Sparkeyy
Nelson

I then want to be able to take these and add them / multiply if they're numbers. This is what I have so far. (Also first question so sorry for poor formatting)

import java.util.*;

public class Program{

public static void main(String args[]){

    System.out.println("Enter your username: ");
    Scanner scanner = new Scanner(System.in);
    String username = scanner.nextLine();
    System.out.println("Your username is " + username);

}
    public static void (name){

        System.out.println("Enter your name: ");
        Scanner scanner = new Scanner(System.in);
        String name     = scanner.nextLine();
        System.out.println("Your name is " + name);

}
}
Ben
  • 51,770
  • 36
  • 127
  • 149
Sparkeyy
  • 11
  • 1
  • You need a method name here `public static void (name){`. You need some sort of array if you want to store multiple inputs, and you need to use loops! – Paul Samsotha Oct 30 '13 at 20:29
  • "(Also first question so sorry for poor formatting)" I guess I'll be that guy; you could have also done the formatting before posting; it's not like we prevent you from doing it. – Dennis Meng Oct 30 '13 at 20:30
  • Are [`Scanner.hasNextInt()`](http://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html#hasNextInt()) and [`Scanner.nextInt()`](http://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html#nextInt()) what you are looking for? – vandale Oct 30 '13 at 20:42

1 Answers1

0

Take a look here, they answered you're question thoroughly:

https://stackoverflow.com/questions/5287538/how-to-get-basic-user-input-for-java

You basically need a Scanner, like you're doing, and then for numbers:

scanner.nextInt();

There are also ways of converting properly formatted Strings to Ints/Doubles.

Community
  • 1
  • 1
Josh T
  • 564
  • 3
  • 12