Unit 1 Intro Lesson 4 Output Output Methods








- Slides: 8

Unit 1: Intro Lesson 4: Output

Output Methods • Output methods allow the program to display information such as text, symbols, numbers, the result of calculations or the value of variables • Most often Output is used to ask to the user for certain information, or to display a result • Output Method 1: System. out. print(“ “); • Output Method 1: System. out. println(“ “); • Output Method 2: JOption. Pane. show. Output. Dialog(“ “);

Print • Simple • Consecutive print statements display on the same line • Can only be used in an IDE or the Command Line

Print Line • Simple • Consecutive print statements display on separate lines • Can only be used in an IDE or the Command Line

JOption. Pane. show. Output. Dialog(“ “); • Slightly more complicated • Works outside of the IDE or Command Line • User – friendly interface • Displays a popup window with the output dialog

Use of Print • Create an initialized variable of any data type to display its value (Optional) • Create an output statement • System. out. print(“How about some input? ”); • int my. Variable = 100; • System. out. print(my. Variable); • String my. Variable = (“Hello there!!!”); • System. out. print(my. Variable);

Use of Print Line • Create an initialized variable of any data type to display its value (Optional) • Create an output statement • System. out. println(“How about some input? ”); • int my. Variable = 100; (Optional) • System. out. println(my. Variable); • String my. Variable = (“Hello there!!!”); • System. out. println(my. Variable); (Optional)

Use of JOption. Pane Output • Import statement • Create an initialized variable of any data type to display its value (Optional) • Create an output statement • Import javax. swing. JOption. Pane; • JOption. Pane. show. Output. Dialog(“You don’t need a variable for me”); • Import javax. swing. JOption. Pane; • int my. Variable = 100; (Optional) • JOption. Pane. show. Output. Dialog(my. Variable); • Import javax. swing. JOption. Pane; • String my. Variable = (“Hello there!!!”); • JOption. Pane. show. Output. Dialog(my. Variable); (Optional)