Try using input.next();
instead of input.nextLine();
Because input.nextLine();
advances this scanner past the current line and returns the input that was skipped. so if your input was 20, +, and 24, your method calc
would get 20,24,null.
Related Contents:
- How to replace all chars in the string except another string in this string
- regex for splitting a string while ignoring the brackets [duplicate]
- How do I count the number of occurrences of a char in a String?
- Java String split removed empty values
- Converting ‘ArrayList to ‘String[]’ in Java
- How to capitalize the first character of each word in a string
- Sort on a string that may contain a number
- What is the purpose of the expression “new String(…)” in Java?
- Occurrences of substring in a string
- How to parse a mathematical expression given as a string and return a number? [duplicate]
- How to convert Java String into byte[]?
- How to convert comma-separated String to List?
- Difference between null and empty (“”) Java String
- Splitting a string at every n-th character
- In Java, is there a way to write a string literal without having to escape quotes?
- How to split a comma-separated string?
- Java String remove all non numeric characters but keep the decimal separator
- Why is String.chars() a stream of ints in Java 8?
- JUnit testing with simulated user input
- How can I replace non-printable Unicode characters in Java?
- How can I get the size of an array, a Collection, or a String in Java?
- How to remove leading zeros from alphanumeric text?
- Format file size as MB, GB, etc [duplicate]
- How to compare character ignoring case in primitive types
- Extract time from date String
- Java String – See if a string contains only numbers and not letters
- Converting List to List
- How to check if a String contains only ASCII?
- Java – removing first character of a string
- StringUtils.isBlank() vs String.isEmpty()
- Extracting pairs of words using String.split()
- How do you pass a string from one activity to another? [duplicate]
- How to remove single character from a String by index
- Print out elements from an Array with a Comma between the elements
- How do format a phone number as a String in Java?
- Creating Unicode character from its number
- substring index range
- Performance penalty of String.intern()
- Whats the best way to recursively reverse a string in Java?
- Split a string, at every nth position
- Extract Integer Part in String
- Java String.replace/replaceAll not working
- How can I start a new android activity using class name in a string?
- The method format(String, Object[]) in the type String is not applicable for the arguments (…)
- Printing reverse of any String without using any predefined function?
- Why does appending “” to a String save memory?
- Convert JsonObject to String
- How to check a string against null in java?
- How do I check if a char is a vowel?
- What is difference between mutable and immutable String in java