In the previous lab, we have setup Eclipse, and written our first Java program that printed "Hello world" to the console screen. Today, we will build on our knowledge and experiment the concepts we learnt in class.
Example:
public static void main(String[] args)
{
int x;
double y;
int a,b,c;
String s1;
...
}
Example: String s2 = "This one contains a default value";
Example: unsigned int x;
Example: int x; String s2= "This one contains a default value"; ... x=1130; String s2= "Now I have changed the content";
Example:
int x=10,z=12,y=30;
if(x==z-2||3>2&&y%10!=2)
{
System.out.println("Statement is true");
}
else
{
System.out.println("Statement is false);
}
String name;
try{
System.out.print("Enter your first name: ");
java.io.DataInputStream in = new java.io.DataInputStream(System.in);
name = in.readLine();
int nameNumber=0;
if(name.equals("Eriks")
nameNumber = 1;
else if(name.equals("Amanda")
nameNumber = 2;
else if(name.equals("Jennifer")
nameNumber = 3;
switch(nameNumber)
{
case 1:System.out.println("Hello Mr.Reks");break;
case 2:System.out.println("Hello Ms.Patterson");break;
case 3:System.out.println("Hello Ms.Wei");break;
default: System.out.println("I'm sorry I don't know you. Please enter your last name:");
String last_name=in.readLine();
System.out.println("Hi "+name+" "+last_name);
}
}
catch(Exception e)
{
System.out.println("I'm sorry. Something extraordinary happened and your program terminated!");
}
Declare integers a,b,c,d;
Assign values into a, b, c, and d
Do the following steps 4 times:
Let I = 1
While (I < 4) do the following:
If the Ith number in the list is greater than the I+1st, then:
Swap the Ith and I+1st numbers in the list.
Add 1 to I
Print out the list.
Save what you have done today in your P: drive (or H:). In this case, you can access your files from Webfiles at home(You will need the examples as a reference manual to finish your assignment).
Submission: Email me your lab3.java file before the class begins on Thursday