0% found this document useful (0 votes)
18 views6 pages

Exercise Lab 17 - 04

Uploaded by

azizibergaming
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views6 pages

Exercise Lab 17 - 04

Uploaded by

azizibergaming
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Muhammad Azizi Bin Jamaludin (301310)

Exercise 17/04/2024

QUESTION 2

package try_stringmethod;

import java.util.Scanner ;

public class Try_stringmethod {

public static void main(String[] args) {

Scanner az = new Scanner (System.in);

String str1 = "Bachelor of Computer Science" ;

String str2 = "School of Computing, UUM" ;

calLength (str1 , str2);

IndexOfC (str1 , str2);

System.out.println("Bachelor " + str2.substring(10,19 ).replace("Bachelor ", ""));

System.out.println(str1.substring(12, str1.length()).replace("Computing", "Computer


Science").toUpperCase());

String str3 = str2.substring(10,19);

find(str3)

public static void calLength (String a , String b){

int indexa = a.length();

System.out.println("Length of str1 : " + indexa);

int indexb = b.length();

System.out.println("Length of str2 : " + indexb);

}
public static void IndexOfC (String a , String b) {

int index1 = a.indexOf('C');

int index2 = b.indexOf('C');

System.out.println("Index of characrer 'C' in str1 : " + index1);

System.out.println("Index of characrer 'C' in str2 : " + index2);

public static void find(String b){

for (int i = 0 ; i < b.length() ; i++){

char az =b.charAt(i);

System.out.println(az);

}
QUESTION 3

package exercise_q3;

import java.util.Scanner ;

public class Exercise_q3 {

public static void main(String[] args) {

Scanner az = new Scanner (System.in);

System.out.print("please enter you number 1 : " );

double num1 = az.nextDouble();

System.out.print("please enter you number 2 : " );

double num2 = az.nextDouble();

double pow = Math.pow( num1, num2 );

double min = Math.min ( num1, num2 );

double max = Math.max (num1 , num2);

System.out.println("The minimum value for two number is " + min );

System.out.println("The maximum value for two number is " + max );

System.out.println("The value of number1 power number2 is " + pow );

}
QUESTION 4

package exercise_q4;

import java.util.Scanner;

import java.util.Random;

public class Exercise_q4 {

public static void main(String[] args) {

Scanner az = new Scanner (System.in);

System.out.print(" initial range : ");

int num1 = az.nextInt();

System.out.print(" final range : ");

int num2 = az.nextInt();

Random randomNum = new Random();

int a = randomNum.nextInt(100);

if (a > num1 && a < num2 ){

int b = a;

System.out.println("Your number is : " + b) ;

else

System.out.println("Your number out of range") ;

}
QUESTION 8

package exercise_q8;

import java.util.Scanner;

public class Exercise_q8 {

public static void main(String[] args) {

Scanner az = new Scanner (System.in);

System.out.print(" Enter Your Stirng : ");

String name = az.nextLine();

String initial = findInitials(name);

System.out.println("Your initials are : " + initial.toUpperCase());

public static String findInitials(String fullname){

String [] word = fullname.split(" ");

char [] nameArray = new char [word.length];

for (int i = 0; i < word.length; i++){

nameArray[i] = word[i].charAt(0);

String findInitials = new String(nameArray);

return findInitials;

You might also like