Please, make sure that you have added the honor code statement at the top of your Java file:
/* THIS CODE IS MY OWN WORK, IT WAS WRITTEN WITHOUT CONSULTING CODE WRITTEN BY OTHER STUDENTS. _Your_Name_Here_ */ |
The deadline for completing this lab assignment is midnight, today.
mkdir ~/cs170/lab5
cp ~cs170002/share/lab5/* ~/cs170/lab5
cd ~/cs170/lab5
|
In this lab, we will use gedit and javac (not BlueJ !).
(You could use BlueJ, but you must figure out how to compile and run the program on your own.)
gedit Sample.java &
|
|
public static void main(String[] args)
{
int i;
/* -----------------------------------------
Make sure user provides 1 argument
----------------------------------------- */
if ( args.length != 1 )
{
System.err.println("Error: Program needs 1 integer as input");
System.exit(1);
}
/* -----------------------------------------
Convert first argument to integer
----------------------------------------- */
int n = Integer.parseInt( args[0] );
/* -----------------------------------------------
Use indentCharLine() to print a nxn square
Print n rows of character 'X' of width n
----------------------------------------------- */
for ( i = 0; i < n; i++ )
{
indentCharLine(1, 'X', n);
}
}
|
javac Sample.java
java Sample 3
Output:
XXX
XXX
XXX
|
gedit Triangle1.java & |
/* **************************************************
+---------+
| TODO: |
+---------+
Use a for-loop to print the following triangle:
X ^
XX |
... | n rows
XXXX |
XXXXX |
XXXXXX v
<---->
base = n
++++ Note: the body of the for-loop uses the method
indentCharLine() !!!
************************************************** */
|
Note:
|
javac Triangle1.java
java Triangle1 7
|
and if correct, you should see this output:
X XX XXX XXXX XXXXX XXXXXX XXXXXXX |
gedit Triangle2.java & |
/* *********************************************************
+---------+
| TODO: |
+---------+
Use a for-loop to print the following triangle:
X ^
XX |
... | n rows
XXXX |
XXXXX |
XXXXXX v
<---->
base = n
++++ Note: the body of the for-loop uses the method
indentCharLine() !!!
********************************************************* */
|
Note:
|
javac Triangle2.java
java Triangle2 7
|
and if correct, you should see this output:
X
XX
XXX
XXXX
XXXXX
XXXXXX
XXXXXXX
|
cd ~/cs170/lab5 /home/cs170002/turnin-lab Triangle1.java lab5 /home/cs170002/turnin-lab Triangle2.java lab5a |
before midnight today.
For the Lead TA:
|