0% found this document useful (0 votes)
6 views

SCD Assignment 1

The document contains a series of Java programming tasks completed by M. Rizwan Ashraf. The tasks include a simple welcome message, basic arithmetic operations, finding the smallest number among three integers, calculating the average of three integers, summing the digits of a number, and checking if one integer is a multiple of another. Each task is implemented in separate classes with corresponding methods.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

SCD Assignment 1

The document contains a series of Java programming tasks completed by M. Rizwan Ashraf. The tasks include a simple welcome message, basic arithmetic operations, finding the smallest number among three integers, calculating the average of three integers, summing the digits of a number, and checking if one integer is a multiple of another. Each task is implemented in separate classes with corresponding methods.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Assignment # 1

M. Rizwan Ashraf
Sp-2022/BSSE/065

Task # 1

public class Assignment1 {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("Welcome to DSE ");

Task # 2
import java.util.Scanner;
public class Arithmatic {
/**
* @param args
*/

public static void main(String[] args) {


Scanner scanner = new Scanner(System.in);

// Prompt the user to enter two integer values


System.out.print("Enter the first integer: ");
float num1 = scanner.nextFloat();

System.out.print("Enter the second integer: ");


float num2 = scanner.nextFloat();

// Perform addition, subtraction, multiplication, and division


float sum = num1 + num2;
float difference = num1 - num2;
float product = num1 * num2;
double division = (double) num1 / num2; // Using double for more precise division

// Print the results


System.out.println("Sum: " + sum);
System.out.println("Difference: " + difference);
System.out.println("Product: " + product);
System.out.println("Division: " + division);

scanner.close();
}
}

Task # 3
1
public class Main {
public static void main(String[] args) {
int num1 = 10;
int num2 = 5;
int num3 = 8;
int smallest = smallNum(num1, num2, num3);
System.out.println("The smallest number among " + num1 + ", " + num2 + ", and " + num3
+ " is: " + smallest);
}

public static int smallNum(int a, int b, int c) {


if (a <= b && a <= c) {
return a;
} else if (b <= a && b <= c) {
return b;
} else {
return c;
}
}
}

2
public class Main {
public static void main(String[] args) {
int num1 = 10;
int num2 = 20;
int num3 = 30;
float average = avg(num1, num2, num3);
System.out.println("The average of " + num1 + ", " + num2 + ", and " + num3 + " is:
" + average);
}

public static float avg(int a, int b, int c) {


return (a + b + c) / 3.0f;
}
}
3
public class Main {
public static void main(String[] args) {
int number = 12345;
float sum = sumOfDigit(number);
System.out.println("Sum of digits of " + number + " is: " + sum);
}

public static float sumOfDigit(int a) {


float sum = 0;
// Using absolute value to handle negative numbers
a = Math.abs(a);
while (a != 0) {
sum += a % 10; // Add the last digit to the sum
a /= 10; // Remove the last digit from the number
}
return sum;
}
}

4
public class Main {
public static void main(String[] args) {
int first = 5;
int second = 15;
String result = multipleOf(first, second);
System.out.println(result);
}

public static String multipleOf(int a, int b) {


if (b % a == 0) {
return b + " is a multiple of " + a;
} else {
return b + " is not a multiple of " + a;
}
}
}

You might also like