Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Lab Sheets/Lab Sheet 02/Lab2Ex1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
public class Lab2Ex1 {
public static void main(String[] args) {
int miles, yards;
double kilometers;
miles = 26;
yards = 365;

kilometers = (miles * 1.609) + (yards * 1.609 / 1760);
System.out.println("Kilometers: " + kilometers);
}
}
7 changes: 7 additions & 0 deletions Lab Sheets/Lab Sheet 02/Lab2Ex2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
public class Lab2Ex2 {
public static void main(String[] args) {
System.out.println("DitNo : " + args[1]);
System.out.println("Name : " + args[0]);
System.out.println("District : " + args[2]);
}
}
16 changes: 16 additions & 0 deletions Lab Sheets/Lab Sheet 02/Lab2Ex3.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import java.util.Scanner;
public class Lab2Ex3 {
public static void main(String[] args) {
int width,length,height,volume;
Scanner input = new Scanner(System.in);
System.out.print("Enter the width of the cube: ");
width = input.nextInt();
System.out.print("Enter the length of the cube: ");
length = input.nextInt();
System.out.print("Enter the height of the cube: ");
height = input.nextInt();
input.close();
volume = width * length * height;
System.out.println("The volume of the cube is: " + volume);
}
}
19 changes: 19 additions & 0 deletions Lab Sheets/Lab Sheet 02/Lab2Ex4.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.IOException;
public class Lab2Ex4 {
public static void main(String[] args) throws IOException{
int width,length,height,volume;

InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
System.out.print("Enter the width of the box: ");
width = Integer.parseInt(br.readLine());
System.out.print("Enter the length of the box: ");
length = Integer.parseInt(br.readLine());
System.out.print("Enter the height of the box: ");
height = Integer.parseInt(br.readLine());
volume = width * length * height;
System.out.print("The volume of the box is: " + volume);
}
}
16 changes: 16 additions & 0 deletions Lab Sheets/Lab Sheet 02/Lab2Ex5/Demo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import java.util.Scanner;
public class Demo {
public static void main(String[] args) {
EvenOddNumber evenOdd = new EvenOddNumber();
int num;
Scanner input = new Scanner(System.in);
System.out.print("Enter a number: ");
num = input.nextInt();
input.close();
if (evenOdd.findEvenOrOdd(num)) {
System.out.println("The number is even.");
} else {
System.out.println("The number is odd.");
}
}
}
9 changes: 9 additions & 0 deletions Lab Sheets/Lab Sheet 02/Lab2Ex5/EvenOddNumber.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
public class EvenOddNumber {
boolean findEvenOrOdd(int i) {
if (i % 2 == 0) {
return true;
} else {
return false;
}
}
}