|
|
| Demonstrating how to print in Java. |
| sillySentances | Tuesday, April 15, 2003, 2002 | By Wulf |
Untitled Document
/* Programmer : Amanda */
/* User ID : abc */
/* Section : 6 */
/* Assignment : Program 2 */
/* Due Date : 02/27/13 */
/* Purpose : Demonstrate understanding of variable declarations and
concatenation. */
/* Input, Output definitions */
import javax.swing.JOptionPane;
public class sillySentances
{
public static void main(String args[])
{
/* Printing out personal information */
System.out.println("\n" + "Programmner : Amanda");
System.out.println("User ID : abc");
System.out.println("Section : 6 ");
System.out.println("Program : 2 ");
System.out.println("Purpose : Concatenation
and variable declaration");
/*Get a word to use in a sentance*/
String noun = JOptionPane.showInputDialog("Enter a noun");
/*Get a number to use in a sentance*/
String str1 = JOptionPane.showInputDialog("Enter your age");
int age = Integer.parseInt(str1);
/*Get a decimal to use in a sentance*/
String str2 = JOptionPane.showInputDialog("Enter a decimal");
double decimal = Double.parseDouble(str2);
/*Make three silly sentances using the values requested above*/
System.out.println("\n" + "My " + noun +" is " + age
+ " years old and it was $" +decimal + " when I bought it.");
System.out.println("My " + 5*age + " degree " +noun+ " is " +
(2+decimal)+ " seconds away from being demolished.");
System.out.println(2*decimal + " is all that it takes for "
+ noun + " to get " + 2*age + " feet away. ");
System.exit(0);
}
}
|
| Output |
If the user input the string flower, the integer 27, and the decimal .01.
Programmner : Amanda
User ID : abc
Section : 6
Program : 2
Purpose : Concatenation and variable declaration practice
My flower is 27 years old and it was $0.01 when I bought it.
My 135 degree flower is 2.01 seconds away from being demolished.
0.02 is all that it takes for flower to get 54 feet away.
|
|
|
| |