diff --git a/Lab1.java b/Lab1.java new file mode 100644 index 0000000..8d7af72 --- /dev/null +++ b/Lab1.java @@ -0,0 +1,34 @@ +* +* +* +* +* + +* * +* * * +* * +* * * +* * + +* * +* * * +* * +* * * +* * + +* * +* * +* * +* * + * * + + 1 2 3 4 + +1 1 2 3 4 + +2 2 4 6 16 + +3 3 6 9 12 + +4 4 8 12 16 + diff --git a/Lab2.java b/Lab2.java new file mode 100644 index 0000000..1e48fa4 --- /dev/null +++ b/Lab2.java @@ -0,0 +1,84 @@ + +/** + * Write a descri + * ption of class Lab2 here. + * + * @author (U15/FNS/CSC/014) ()ry*+= + */ +import java.util.Random; +public class Lab2 +{ + public static void main(String[]args){ + double miles=10.5; + miles=10.5; + miles++; + System.out.println("\nEXERCISES 01a MILES"); + System.out.println("The correct value of miles is now: "+miles+"\n"); +System.out.println("\bEXERCISES 01b COMPUTE XYZ"); + double x,y,z; + int a= 1; double d= 1.0; + x= d+43%5*(23*3%2); + y= 1.5*3+(++a); + z= 3+d*d+4; + System.out.println("The value of x: "+x); + System.out.println("The value of y: "+y); + System.out.println("The value of z: "+z); +System.out.println("\nEXERCISES 01c R= Math.log(P) "); + double R,P; + P=3.758; + R= Math.log(P); + System.out.println("The solution = "+R); +System.out.println("\nEXERCISES 02 MATHFUNCTION"); + double k; + k=2/4*4%3; + //converting from degrees to radian + double cos=Math.cos(Math.toRadians(30)); + double sin=Math.sin(Math.toRadians(30)); + double tan=Math.tan(Math.toRadians(30)); + System.out.println("The value of cos 30: "+cos); + System.out.println("The value of exp(15): "+Math.exp(15)); + System.out.println("The value of sin 30: "+sin); + System.out.println("The absolute value of k is "+Math.abs(k)); + System.out.println("The value of tan 30: "+tan); +System.out.println("\nEXERCISES 03 USERNAME&DOMAIN"); + String email,domain,username; + email = "Phoenixkheeng@gmail.com"; + username = email.split("@")[0]; + domain = email.substring(email.indexOf("@")+1); + //username = email.substring(email.indexOf("@")-1); + System.out.println("The email address==> Phoenixkheeng@gmail.com"); + System.out.println("Username:"+ username); + System.out.println("Domain:"+ domain); +System.out.println("\nEXERCISES 04 FILENAME&EXTENSION"); + String path; + path = "d:phoenixkheeng/work/lab2.java"; + int index=path.lastIndexOf("/"); + int ext=path.lastIndexOf("."); + String fileName=path.substring(index+1, ext); + String filePath=path.substring(0, index); + String fileExt=path.substring(ext+1); + System.out.println("This is the path entered ==> d:phoenixkheeng/work/lab2.java"); + System.out.println("The Fullname: "+path); + System.out.println(" The Directory: "+filePath+" \n The Filename: "+fileName+" \n The Extension: "+fileExt); +System.out.println("\nEXERCISES 05 PASSWORD GENERATOR"); + String firstName = "abdullah"; + String middleName = "muhammed"; + String lastName = "abdullahi"; + Random rand = new Random(); + for(int icount=0;icount<10;icount++){ + int randomNumber = rand.nextInt(100); + } + int age = 20; + // int zaa = age+randomNumber; + //extract initials + String initials = + firstName.substring(0,1)+ + middleName.substring(0,1)+ + lastName.substring(3,4); + //append age + String password =(initials.toLowerCase()); + //password+randomNumber; + System.out.println("Your Password = "+password); + + } +} diff --git a/Lab3.java b/Lab3.java new file mode 100644 index 0000000..fbc9ee8 --- /dev/null +++ b/Lab3.java @@ -0,0 +1,64 @@ + +/** + * Write a description of class Lab3 here. + * + * @author (your name) + * @version (a version number or a date) + */ +import java.util.Scanner; +public class Lab3 +{ + public static void main(String[]arg){ +System.out.println("\nEXERCISES 01 Volume&Surface-area"); +Scanner scann = new Scanner(System.in); +System.out.println("Enter the length:"); +double l = scann.nextDouble(); +System.out.println("Enter the width:"); +double w = scann.nextDouble(); +System.out.println("Enter the heigth:"); +double h = scann.nextDouble(); +double volume = (h*w*l); +double surface = 2*(l*w+l*h+w*h); +System.out.println("The volume of the box: "+volume); +System.out.println("The surface area of the box: "+surface); +System.out.println("\nEXERCISES 02 USERNAME&DOMAIN"); + Scanner scan = new Scanner(System.in); + String domain,username; + System.out.println("Please enter a valid email address"); + String email = scan.nextLine(); + username = email.split("@")[0]; + domain = email.substring(email.indexOf("@")+1); + //username = email.substring(email.indexOf("@")-1); + System.out.println("\nUsername:"+ username); + System.out.println("Domain:"+ domain); + +System.out.println("\nEXERCISES 03 Perimeter&Area"); + Scanner scan1 = new Scanner(System.in); + System.out.println("Enter the 1st sides:"); + int a = scan1.nextInt(); + System.out.println("Enter the 2nd sides:"); + int b = scan1.nextInt(); + System.out.println("Enter the 3rd sides:"); + int c = scan1.nextInt(); + double s =(a+b+c)/2; + double area = Math.sqrt(s*(s-a)*(s-b)*(s-c)); + System.out.println("The Perimeter of triangle is: "+s); + System.out.println("The area of the triangle with the input sides is "+ area+"unit square"); + if(a>b && a>c){ + System.out.println("The longest side is: "+a); + }else if(b>c){ + System.out.println("The longest side is: "+b); + }else{ + System.out.println("The longest side is: "+c); + } + + if(a