Results 1 to 4 of 4
- 10-21-2012, 06:48 PM #1
Member
- Join Date
- Oct 2012
- Posts
- 28
- Rep Power
- 0
Using Scanner in a selfcheck exercise
Hi I got a selfcheck exercise, where I'm supposed to make a program that prints the following(example) "Hello there. 1+2 is 3", where I have to be able to type in values as if it was a+b = c.
This is working, but how do I add text before the output that comes when I have entered a and b's values? I want it to show the line "Hello there. a + b is c, choose a value for a". and then same line just with b instead of a, for when I have to give b a value.Java Code:import java.util.*; public class SelfCheck_3_16 { public static void main(String[] args) { Scanner console = new Scanner(System.in); int a = console.nextInt(); int b = console.nextInt(); int c = a+b; System.out.println("Hello there. " +a +" + " +b +" is " + c); } }
Hope I make any sense :)
-
Re: Using Scanner in a selfcheck exercise
Consider placing System.out.print(...) or System.out.println(...) statements before the statements where you obtain your nextInt() from the Scanner object.
- 10-21-2012, 06:55 PM #3
Member
- Join Date
- Oct 2012
- Posts
- 28
- Rep Power
- 0
Re: Using Scanner in a selfcheck exercise
I see, thank you for helping me!
-
Similar Threads
-
Need Serious Help on Odometer exercise
By gnng in forum New To JavaReplies: 16Last Post: 03-20-2011, 06:58 PM -
Have I done this exercise right?
By ccie007 in forum New To JavaReplies: 7Last Post: 09-28-2010, 05:54 PM -
Exercise for java 3d
By armiri in forum Java SoftwareReplies: 3Last Post: 05-13-2010, 11:13 PM -
I/O exercise
By Feldom in forum New To JavaReplies: 1Last Post: 10-28-2007, 04:48 PM -
help with exercise
By e_as're in forum New To JavaReplies: 3Last Post: 09-25-2007, 10:14 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks