.nextLine(); only picks up first word
Code:
import java.util.Scanner;
public class Multiples
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
System.out.print("***************************************\n* Welcome to your first Java program! *\n***************************************\n\n*** Test integer arithmetic ***\n\nEnter first integer number: ");
int intone = keyboard.nextInt();
System.out.print("Enter second integer number: ");
int inttwo = keyboard.nextInt();
System.out.println(intone+" + "+inttwo+" = "+(intone+inttwo));
System.out.println(intone+" - "+inttwo+" = "+(intone-inttwo));
System.out.println(intone+" * "+inttwo+" = "+(intone*inttwo));
System.out.println(intone+" / "+inttwo+" = "+(intone/inttwo));
System.out.println(intone+" % "+inttwo+" = "+(intone%inttwo));
System.out.print("\n*** Test real artithmetic ***\n\nEnter first real number: ");
double realone = keyboard.nextDouble();
System.out.print("Enter second real number: ");
double realtwo = keyboard.nextDouble();
System.out.println(realone+" + "+realtwo+" = "+(realone+realtwo));
System.out.println(realone+" - "+realtwo+" = "+(realone-realtwo));
System.out.println(realone+" * "+realtwo+" = "+(realone*realtwo));
System.out.println(realone+" / "+realtwo+" = "+(realone/realtwo));
System.out.print("\n*** Test String operations ***\n\nEnter a string of characters: ");
String stringone = keyboard.nextLine();
System.out.print("The length of the string \""+stringone+"\" is "+s1.length());
System.out.print("\nEnter an integer between 0 and "+(stringone.length()-1)+": ");
int stringindex = keyboard.nextInt();
System.out.println("The character at index "+stringindex+" of string \""+s1+" is ''"+s1.charAt(stringindex)+"''");
}
}
After entering a string of characters with multiple words it prints out only the first word of the string.
example:
*** Test String operations ***
Enter a string of characters: test test
The length of the string test is 4