You're getting the toString() value returned by the Scanner object itself which is not what you want and not how you use a Scanner object. What you want instead is the data obtained by the Scanner object. For example,

Scanner input = new Scanner(System.in);
String data = input.nextLine();
System.out.println(data);

Please read the tutorial on how to use it as it will explain all.

Edit
Please look here: Scanner tutorial

Also have a look at the Scanner API which will explain some of the finer points of Scanner's methods and properties.

Answer from Hovercraft Full Of Eels on Stack Overflow
🌐
W3Schools
w3schools.com › java › java_variables_print.asp
Java Print/Display Variables
Java Examples Java Videos Java ... To combine both text and a variable, use the + character: String name = "John"; System.out.println("Hello " + name);...
🌐
Sololearn
sololearn.com › en › Discuss › 2568004 › how-do-i-print-out-a-letter-and-space-only-from-a-string-in-java
How do I print out a letter and space only from a string in Java? | Sololearn: Learn to code for FREE!
October 29, 2020 - Make a new empty String variable to hold the output string String output = "". Now all you need to do is loop over the elements of the char array and check if each element is either a letter "Character.isLetter(ch)" or a space "Character.is...
Discussions

Learning java, need help understanding why I can't print this.
I just replicated your program in an abridged, minimal runnable version: https://ideone.com/OwIYvI And there, it runs without error. Contrary to what everybody else in this thread says, your program should run as my ideone from above proves. The suggestions to use a wrapper type are plain wrong as printf is absolutely supposed to work with primitives. My code that works on ideone: import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ class Ideone { public static void main (String[] args) throws java.lang.Exception { // your code goes here int ageYears, weightPounds, heartRate, timeMinutes; float avgCalorieBurn; ageYears = 49; weightPounds = 155; heartRate = 148; timeMinutes = 60; avgCalorieBurn = ((ageYears * 0.2757f) + (weightPounds * 0.03295f) + (heartRate * 1.0781f) - 75.4991f) * timeMinutes / 8.368f; System.out.printf("Calories: %.2f",avgCalorieBurn); } } The code is basically identical to yours, except for the naming. More on reddit.com
🌐 r/javahelp
24
2
February 6, 2024
The fastest way to print a string in java i could think of. if there's a faster way besides iterating through eveyr possible string please let me know :( cause right now this is O(2^7n) which is not very fast and I need to print hello world by tomorrow (happy april fools)
It's r/programmerhumour everyday is April fools More on reddit.com
🌐 r/ProgrammerHumor
4
24
January 21, 2023
[JAVA] Difference between creating a print method and using toString method?
In this line: System.out.println(bond) the println method calls the bond object's toString method to determine what to print. This is because the println method looks at the Agent class's toString method to determine how to make a String out of an Agent object. Because both Agent.toString and Agent.print create similar String objects, both method calls print the same information The difference is that you could store the String object returned by toString for later. Let's say you wanted to keep a description of bond for later: String description = bond.toString(); You could then reference description whenever you wanted, manipulate it, maybe save the description to a file somewhere, etc. The Agent.print method throws away the String that's made after printing, and creates a new one each time you call it, which is less memory- and CPU-efficient You could also make your code more maintainable by simply changing the print method to print like this: System.out.println(this); This would make println call the Agent.toString method, requiring you to only upkeep a single method More on reddit.com
🌐 r/learnprogramming
6
13
December 5, 2020
Why does this code not print the Strings equal?: part

Please ensure that:

  • Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions

  • You include any and all error messages in full

  • You ask clear questions

  • You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions.

    Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar

If any of the above points is not met, your post can and will be removed without further warning.

Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc.

Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit.

Code blocks look like this:

public class HelloWorld {

    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
}

You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above.

If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures.

To potential helpers

Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

More on reddit.com
🌐 r/javahelp
13
4
May 29, 2022
🌐
GeeksforGeeks
geeksforgeeks.org › dsa › how-to-print-or-output-a-string
How to print or output a String? - GeeksforGeeks
July 23, 2025 - In this article, we are going to learn how to print or output a string using different languages. Strings are considered a data type in general and are typically represented as arrays of bytes (or words) that store a sequence of characters.
🌐
W3Schools
w3schools.com › java › java_output.asp
Java Output Values / Print Text
Java Wrapper Classes Java Generics Java Annotations Java RegEx Java Threads Java Lambda Java Advanced Sorting ... How Tos Add Two Numbers Swap Two Variables Even or Odd Number Reverse a Number Positive or Negative Square Root Area of Rectangle Celsius to Fahrenheit Sum of Digits Check Armstrong Num Random Number Count Words Count Vowels in a String Remove Vowels Count Digits in a String Reverse a String Palindrome Check Check Anagram Convert String to Array Remove Whitespace Count Character Frequency Sum of Array Elements Find Array Average Sort an Array Find Smallest Element Find Largest Element Second Largest Array Min and Max Array Merge Two Arrays Remove Duplicates Find Duplicates Shuffle an Array Factorial of a Number Fibonacci Sequence Find GCD Check Prime Number ArrayList Loop HashMap Loop Loop Through an Enum
🌐
Educative
educative.io › home › courses › the complete java crash course › printing to the screen
Java Screen Printing Methods and String Formatting
Learn how to print to the screen in Java, including the use of System.out.println, string concatenation, special characters, and formatted output.
🌐
TheServerSide
theserverside.com › blog › Coffee-Talk-Java-News-Stories-and-Opinions › How-to-format-a-Java-String-with-printf-example
How to format a Java String with printf example
Use %S as the printf String specifier to output upper-case text. Precede the letter s with a number to specify field width. Put a negative sign after the % to left-justify the text.
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › java › strings-in-java
Java Strings - GeeksforGeeks
StringBuilder in Java represents an alternative to String and StringBuffer Class, as it creates a mutable sequence of characters and it is not thread safe.
Published   January 13, 2026
🌐
Medium
medium.com › javarevisited › java-output-a-beginners-guide-to-printing-text-7aad93774110
Java Output: A Beginner’s Guide to Printing Text | by Mouad Oumous | Javarevisited | Medium
September 15, 2024 - You can use this technique to combine any type of variable with strings for a more customized output. Use `println()` for clarity: As mentioned earlier, println() makes the code and output easier to read, especially when displaying multiple lines of information. It’s the default method for most print tasks in Java, especially for beginners.
🌐
Just Academy
justacademy.co › blog-detail › how-to-print-a-string-in-java
How to Print a String in Java
9) Use Java IO classes: Explore different Java IO classes such as FileWriter, FileOutputSteam, or PrintWriter to print strings to files on disk. 10) Read user input: You can use the Scanner class to read input from the user and then print the input as a string using System.out.println().
🌐
W3Schools
w3schools.com › java › ref_output_printf.asp
Java Output printf() Method
Java Examples Java Videos Java Compiler Java Exercises Java Quiz Java Code Challenges Java Server Java Syllabus Java Study Plan Java Interview Q&A Java Certificate ... Print some formatted text to the console. The %s character is a placeholder for the string "World":
🌐
TheServerSide
theserverside.com › blog › Coffee-Talk-Java-News-Stories-and-Opinions › Java-String-input-with-the-Scanner-class
Java Scanner String input example
The following example uses the Java Scanner class to take String input from the user: import java.util.Scanner; public class ScannerUserInput { public static void main(String[] args) { // String input with the Java Scanner System.out.println("How old are you?"); Scanner stringScanner = new Scanner(System.in); String age = stringScanner.next(); System.out.println(age + " is a good age to be!"); } }
🌐
Baeldung
baeldung.com › home › java › core java › formatting output with printf() in java
Formatting Output with printf() in Java | Baeldung
January 8, 2024 - The second rule adds a newline character to the end of the string. Let’s have a look at format string more closely. It consists of literals and format specifiers. Format specifiers include flags, width, precision, and conversion characters in this sequence: ... Specifiers in the brackets are optional. Internally, printf() uses the java.util.Formatter class to parse the format string and generate the output.
🌐
Scaler
scaler.com › home › topics › print in java with examples
Print in Java with Examples - Scaler Topics
September 26, 2023 - It is used when the user is required to print the results on different lines. The printf() method in Java is used to print the formatted string to the console using the given format string and arguments.
🌐
Python
docs.python.org › 3 › library › string.html
string — Common string operations
'left<<<<<<<<<<<<' '^^^^^center^^^^^' '>>>>>>>>>>>right' >>> >>> octets = [192, 168, 0, 1] >>> '{:02X}{:02X}{:02X}{:02X}'.format(*octets) 'C0A80001' >>> int(_, 16) 3232235521 >>> >>> width = 5 >>> for num in range(5,12): ... for base in 'dXob': ... print('{0:{width}{base}}'.format(num, base=base, width=width), end=' ') ... print() ... 5 5 5 101 6 6 6 110 7 7 7 111 8 8 10 1000 9 9 11 1001 10 A 12 1010 11 B 13 1011 ... The feature described here was introduced in Python 2.4; a simple templating method based upon regular expressions. It predates str.format(), formatted string literals, and template string literals. It is unrelated to template string literals (t-strings), which were introduced in Python 3.14.
🌐
TutorialsPoint
tutorialspoint.com › java-program-to-print-a-string
Java Program to Print a String
June 14, 2024 - Step 1- START Step-2- Declare a string Step 3- Prompt the user to enter a string/ define the string in a variable Step 4- Read the value Step 5- Display it on the console Step 6- STOP · Here, the input is being entered by the user based on a prompt. You can try this example live in our coding ground tool . import java.util.Scanner; public class PrintString { public static void main(String[] args){ String my_str; System.out.println("The required packages have been imported "); Scanner my_scan = new Scanner(System.in); System.out.print("A scanner object has been defined \n"); System.out.print("Enter a string:"); my_str = my_scan.nextLine(); System.out.print("The nextLine method is used to read the string"); System.out.println("The string is: "); System.out.println(my_str); } }
🌐
Programiz
programiz.com › java-programming › string
Java String (With Examples)
We use double quotes to represent a string in Java. For example, // create a string String type = "Java programming"; Here, we have created a string variable named type. The variable is initialized with the string Java Programming. class Main { public static void main(String[] args) { // create strings String first = "Java"; String second = "Python"; String third = "JavaScript"; // print strings System.out.println(first); // print Java System.out.println(second); // print Python System.out.println(third); // print JavaScript } }
🌐
Oracle
docs.oracle.com › javase › tutorial › java › data › numberformat.html
Formatting Numeric Print Output (The Java™ Tutorials > Learning the Java Language > Numbers and Strings)
There are many converters, flags, and specifiers, which are documented in java.util.Formatter ... The %d specifies that the single variable is a decimal integer. The %n is a platform-independent newline character. The output is: ... The printf and format methods are overloaded. Each has a version with the following syntax: public PrintStream format(Locale l, String format, Object... args) To print numbers in the French system (where a comma is used in place of the decimal place in the English representation of floating point numbers), for example, you would use:
🌐
Coderanch
coderanch.com › t › 649175 › java › string-printing-digits
Taking a string and printing only the digits (Beginning Java forum at Coderanch)
To support this you'll probably want a class instance field called 'number' that is a String. I highly recommend that you look up the StringBuilder class API documentation, and specifically, its append() method. JavaRanch-FAQ HowToAskQuestionsOnJavaRanch UseCodeTags DontWriteLongLines ItDoesntWorkIsUseLess FormatCode JavaIndenter SSCCE API-17 JLS JavaLanguageSpecification MainIsAPain KeyboardUtility
🌐
Coderanch
coderanch.com › t › 411681 › java › print-reference-String-Object
How to print reference of String Object ? (Beginning Java forum at Coderanch)
September 1, 2008 - But today when i created a reference of String class and tried printing the same i got the value as output not the Address. When i checked the String class source code i came to know that String class has overridden the toString() method which it inherited from Object class.