import java.io.*;
public class Exercise1
{
public static void main (String argv[])
{
System.out.println("My name
is:");
System.out.println("Bob
Hartley");
System.out.println("and I'm
learning Java.");
}
}
import java.io.*;
public class Exercise2
{
public static void main (String argv[])
{
System.out.println("My name
is:\nBob Hartley\nandI'm learning Java.");
}
}
import java.io.*;
public class Exercise3
{
public static void main (String argv[])
{
String name;
double price;
boolean in_stock;
int group_number;
name="Gone With the Wind";
price=2.15;
in_stock=true;
group_number=3;
System.out.println(name);
System.out.println("Rents for:
$" + price);
System.out.println("In stock:
" + in_stock);
System.out.println("Group:
" + group_number);
}
}
answers will vary
import java.io.*;
public class Exercise5
{
public static void main (String argv[])
{
double x, y;
x=3;
y=6;
System.out.println(x + " + " + y
+ " = " + (x+y));
System.out.println(x + " - " + y
+ " = " + (x-y));
System.out.println(x + " * " + y
+ " = " + (x*y));
System.out.println(x + " / " + y
+ " = " + (x/y));
}
}
import java.io.*;
public class Exercise6
{
public static void main (String argv[])
{
double x, y;
x=3;
y=6;
System.out.println(x
+ " + " + y + " = " + (x+y));
x++;
System.out.println(x
+ " - " + y + " = " + (x-y));
x--;
System.out.println(x
+ " * " + y + " = " + (x*y));
System.out.println(x
+ " / " + y + " = " + (x/y));
}
}
import java.io.*;
public class Exercise7
{
public static void main (String argv[])
{
int age;
age=31;
if ( age >= 21)
System.out.println( "Eligible to vote ");
else
System.out.println("Not eligible.");
}
}
import java.io.*;
public class Exercise8
{
public static void main (String argv[])
{
string day=”Tuesday”;
if ( day == “Saturday” || day == “Sunday” )
System.out.println( "Weekend");
else
System.out.println("Weekday");
}
}
import java.io.*;
public class Exercise9
{
public static void main (String argv[])
{
int grade=8;
if ( grade < 7 )
System.out.println( "Elementary");
else if ( grade < 9 )
System.out.println("Junior High");
else
System.out.println("High School");
}
}
import java.io.*;
public class Exercise10
{
public static void main (String argv[])
{
int year_of_birth = 1960;
switch ( year_of_birth % 12 )
{
case 0:
System.out.println("You
were born in “ + year_of_birth + “, the year of the Monkey");
break;
case 1:
System.out.println("You
were born in “ + year_of_birth + “, the year of the Rooster");
break;
case 2:
System.out.println("You
were born in “ + year_of_birth + “, the year of the Dog");
break;
case 3:
System.out.println("You
were born in “ + year_of_birth + “, the year of the Pig");
break;
case 4:
System.out.println("You
were born in “ + year_of_birth + “, the year of the Rat");
break;
case 5:
System.out.println("You
were born in “ + year_of_birth + “, the year of the Ox");
break;
case 6:
System.out.println("You
were born in “ + year_of_birth + “, the year of the Tiger");
break;
case 7:
System.out.println("You
were born in “ + year_of_birth + “, the year of the Rabbit");
break;
case 8:
System.out.println("You
were born in “ + year_of_birth + “, the year of the Dragon");
break;
case 9:
System.out.println("You
were born in “ + year_of_birth + “, the year of the Snake");
break;
case 10:
System.out.println("You
were born in “ + year_of_birth + “, the year of the Horse");
break;
case 11:
System.out.println("You
were born in “ + year_of_birth + “, the year of the Sheep");
break;
default:
System.out.println("Error");
break;
}
}
}
import java.io.*;
public class Exercise11
{
public static void main (String argv[])
{
for
( int i = 10; i > 0; i--
)
{
System.out.println
( i );
}
}
}
import java.io.*;
public class Exercise12
{
public static void main (String argv[])
{
int i = 10;
while
( i > 0 )
{
System.out.println
( i );
i--;
}
}
}
import java.io.*;
public class Exercise13
{
public static void main (String argv[])
{
int i = 10;
do
{
System.out.println
( i );
i--;
} while
( i > 0 ) ;
}
}