/*** Class for creating a template for a simple Java program** @author Pat Troy: troy AT uic DOT edu */// Note the name of the class in the following line MUST// match the name of the file. This is stored in a file// named: Template.javapublic class Template{public static void main (String[] args){System.out.println("Begin Java Exection");System.out.println("");// put your Java Program hereSystem.out.println("");System.out.println("End Java Exection");}}// end of Template class
System.out.println ("Hello. Hope you have a good day.");To print out a number or the value of a variable, we place that information between the parenethesis. For example:
System.out.println (57);
System.out.println (number);We can print both some text and a value by placing both of these in between the parenthesis and separating them with a + sign, such as:
System.out.println ("The result of the operation is " + number);Note, there also exists a method System.out.print(). This method will have the next printed item begin on the same line as this one ends. The System.out.println() always has the next printed item begin at the beginning of the next line. Also note that to print a blank line in the output (i.e. to skip a line), use System.out.println() with nothing between the parathesis. In the program Template.java, this same thing was done by printing an empty string:
System.out.println("");Both produce the same result. You will notice that often the same result can be produced via different approaches.
As I was going to St. Ives,
I met a man with seven wives,
Every wife had seven sacks,
Every sack had seven cats,
Every cat had seven kits,
Kits, cats, sacks, wives,
How many were going to St. Ives?
Just storing the value of 7 into the variable numWives is not enough for full credit for the assignment. You are also required display the values in the variables when showing the information about who the narrator met. When doing this you must also display some text describing any values prior to displaying the values. For example://declaring variablesint numMan;int numWives;numMan = 1; // determining the number of mennumWives = numMan * 7; // determining the number of wives
Submission of the Lab The lab must be submitted electronically to the Assignment Link for Lab 1 inside of Blackboard. You will only need to submit the java source code file (just the ".java" file, not the ".java~" file or the ".class" file). You are to name your program file (and the class) using both your NET-ID and the Lab Number. Thus for Lab 1, if you NET-ID was ptroy4, your program should be named: Ptroy4Lab1.java -- Main.troy - 2014-09-05System.out.println ("The number of wives are: " + numWives);
I![]() |
Attachment | Action | Size | Date | Who | Comment |
---|---|---|---|---|---|---|
![]() |
st_ives.jpg | manage | 32.8 K | 2014-09-05 - 19:44 | UnknownUser |
Copyright 2016 The Board of Trustees of the University of Illinois.webmaster@cs.uic.edu |
WISEST Helping Women Faculty Advance Funded by NSF | ![]() | ![]() |