import java.io.*;
public class MoreEx1
{
public static void main ( String argv[])
{
int a,b,c;
a=15;
b=6;
c= a +b;
System.out.println("The sum of a and b is " + c );
c= a% b;
System.out.println("a mod b is " + c );
}
}
import java.io.*;
public class MoreEx2
{
public static void main ( String argv[])
{
float a,b;
a=17;
b=3;
String result = "The answer is ";
System.out.println(result + (a / b));
}
}
import java.io.*;
public class MoreEx3
{
public static void main ( String argv[])
{
String fname="Bob", lname="Hartley", mname="I";
int age=45;
System.out.println(lname + ", " + fname+"\n");
System.out.println(age);
}
}
4. Print the line “This is a loop test” on the screen 3 times, on three separate lines.
import java.io.*;
public class MoreEx4
{
public static void main ( String argv[])
{
for (int x = 1; x <=3; x++ )
System.out.println("This is a loop test.");
}
}
5. Print the line “This is a loop test” on the screen 3 times, with a space between each line.
import java.io.*;
public class MoreEx5
{
public static void main ( String argv[])
{
for (int x = 1; x <=3; x++ )
System.out.println("This is a loop test.\n");
}
}
6. Print on the screen (using a loop, of course), this:
This is line 1.
This is line 2.
This is line 3.
import java.io.*;
public class MoreEx6
{
public static void main ( String argv[])
{
for (int x = 1; x <=3; x++ )
System.out.println("This is line "+x+".");
}
}
7. Print on the screen these lines:
46. This is a line.
47. This is a line.
48. This is a line.
import java.io.*;
public class MoreEx7
{
public static void main ( String argv[])
{
for (int x = 46; x <=48; x++ )
System.out.println(x +". "+"This is a line.");
}
}
import java.io.*;
public class MoreEx8
{
public static void main ( String argv[])
{
int x = 42;
if ( x % 2 == 0 )
System.out.println("Even");
else
System.out.println("Odd");
}
}
import java.io.*;
public class MoreEx9
{
public static void main ( String argv[])
{
int x = 2;
if ( x == 2 )
System.out.println("It's a 2.");
else if ( x == 3 )
System.out.println("It's a 3 ");
else
System.out.println("It's something else.");
}
}