| | |
Scanner Input from Keyboard help
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Sep 2008
Posts: 9
Reputation:
Solved Threads: 0
Hi, I'm trying to write a java program that will read in the scanner input from a user and outputs an postfix expression and answer
so if you typed in:
A = 5
B = 7
$PART2
AB+
the output would be
AB+ = 12
I'm having trouble with the scanner input I can make it so a user
can enter a letter and a number, but I'm having trouble trying to make the program shift so when the user enters $PART2 it will then begin to read in the post fix expressions.
If anyone could help I would greatly appreciate it.
so if you typed in:
A = 5
B = 7
$PART2
AB+
the output would be
AB+ = 12
I'm having trouble with the scanner input I can make it so a user
can enter a letter and a number, but I'm having trouble trying to make the program shift so when the user enters $PART2 it will then begin to read in the post fix expressions.
If anyone could help I would greatly appreciate it.
Java Syntax (Toggle Plain Text)
import java.util.*; import java.io.*; import java.util.Scanner; import java.util.Stack; public class PostEval { static public void main(String args[]) { Scanner scanner = new Scanner(System.in); Stack<String> postFix = new Stack<String>(); String part2 = "$PART2"; System.out.println("Input Letter and Number it equals: "); while(scanner.hasNext()) { String letter = scanner.next(); char equals=(scanner.next()).charAt(0); int number = scanner.nextInt(); System.out.println("You Inputted:"+ letter+ equals+ number); if(letter == "$PART2") { while(scanner.hasNext()) { String postfix = scanner.nextLine(); System.out.println(postfix); } } }
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."
"How to ask questions the smart way ?"
"How to ask questions the smart way ?"
![]() |
Similar Threads
- Scanner or BufferedReader ? (Java)
- Problem on using keyboard wedge Barcode scanner with VBA (Visual Basic 4 / 5 / 6)
- Reading Keyboard Data Direct From Port (Perl)
- how to read input from barcode scanner? (PHP)
- Converting lowercase type to uppercase (new programmer) (Java)
- Moniter Refresh/Flicker problem (Troubleshooting Dead Machines)
- Reading from USB port using php? (PHP)
Other Threads in the Java Forum
- Previous Thread: Problem with List<E>
- Next Thread: Full-Screen Exclusive Mode: "Display Modes" question
| Thread Tools | Search this Thread |
2dgraphics account android api apple applet application array arrays automation banking binary binarytree bluetooth chat chatprogramusingobjects class classes client code component data database derby design draw eclipse encryption error event exception fractal game givemetehcodez graphics gui html ide if_statement image inheritance input integer interface j2me java javadesktopapplications javaprojects jlabel jni jpanel jtextfield julia linux list loop map method methods midlethttpconnection mobile monitoring netbeans newbie nullpointerexception open-source oracle print printing problem program programming project property recursion reference ria scanner screen search server set size sms sort sourcelabs splash sql static stop string swing testautomation threads time tree ui unicode validation windows






