0% found this document useful (0 votes)
11 views16 pages

FA24-BCS-045

The document contains a programming assignment by Muhammad Abdullah Riaz for the subject Programming Fundamental, consisting of 14 tasks. Each task involves writing Java programs that perform various operations such as calculating quotients, swapping numbers, reversing digits, and converting units. The assignment showcases fundamental programming concepts and basic arithmetic operations using Java.

Uploaded by

85abdullahmalik
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)
11 views16 pages

FA24-BCS-045

The document contains a programming assignment by Muhammad Abdullah Riaz for the subject Programming Fundamental, consisting of 14 tasks. Each task involves writing Java programs that perform various operations such as calculating quotients, swapping numbers, reversing digits, and converting units. The assignment showcases fundamental programming concepts and basic arithmetic operations using Java.

Uploaded by

85abdullahmalik
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/ 16

ASSIGNMENT NO 1

NAME: MUHAMMAD ABDULLAH RIAZ

ROLL NO: FA24-BCS-045

SECTION: BCS-2-A

SUBJECT: PROGRAMMING FUNDAMENTAL

SUBMITTED TO: FAYEZ AFZAL


1-Develop a program that inputs dividend and divisor. It then calculates and displays the
quotient and remainder.

import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
System.out.println("Enter an dividend value");
int a=input.nextInt();
System.out.println("Enter an divisor value");
int b=input.nextInt();
int quotient= a/b;
int remainder=a%b;
System.out.println("Enter a quotient value"+quotient);
System.out.println("Enter a remainder value"+remainder);

}
}
2-Construct a program that inputs two numbers swaps the values and then displays them.
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
System.out.println("Enter number 1");
int num1=input.nextInt();

System.out.println("Enter an number 2");


int num2=input.nextInt();
int temp=num1;
num1=num2;
num2=temp;
System.out.println("num1: "+num1+" num2: "+num2);
}
}
3-Solve a program that inputs two numbers swaps these values without using the third
variable and displays them.
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
System.out.println("Enter number 1");
int num1=input.nextInt();
System.out.println("Enter an number 2");
int num2=input.nextInt();
num1=num1+num2;
num2=num1-num2;
num1=num1-num2;
System.out.println("num1: "+num1+" num2: "+num2);
}
}
4-Develop a program that inputs a five-digit number as input and reverse the number

import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
System.out.print("Enter a five-digit number: ");
int number = scanner.nextInt();
if (number < 10000 || number > 99999) {
System.out.println("Please enter a valid five-digit number.");
} else {
int reversedNumber = (number % 10) * 10000 +
((number / 10) % 10) * 1000 +
((number / 100) % 10) * 100 +
((number / 1000) % 10) * 10 +
(number / 10000);
System.out.println("The reversed number is: " + reversedNumber);
}
}
}
5-Construct a program that inputs an even and odd number through keyboard, multiplies
even with 5 and odd with 3 and adds both results. It subtracts the result from 1000 and
finally prints the difference
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
System.out.println("Enter an even num");
int even = scanner.nextInt();
System.out.println("Enter an odd num");
int odd = scanner.nextInt();
int result=(even*5) +(odd*3);
int difference=1000-result;
System.out.println("difference is "+difference);
}
}
6- Solve a program that will prompt the user to enter the number of hours. It computes and
displays the number of weeks and days.
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
System.out.print("Enter the number of hours: ");
int hours = scanner.nextInt();
int weeks = hours / (24 * 7);
int remainingHours = hours % (24 * 7);
int days = remainingHours / 24;
System.out.println("Equivalent time: " + weeks + " weeks and " + days + " days.");
}
}
7- Develop a program that inputs miles from the user and convert miles into kilometres

import java.util.Scanner;

public class Main {

public static void main(String[] args) {


Scanner scanner= new Scanner(System.in);

System.out.println("Enter distance in miles");

double miles=scanner.nextDouble();

double kilometers=miles*1.60934;

System.out.println(miles + " miles equal to " + kilometers + " kilometers");


}
}
8- Construct a program that inputs 4 numbers and calculates the sum, average and product
of all numbers
import java.util.Scanner;

public class Main {


public static void main(String[] args) {
Scanner scanner= new Scanner(System.in);
System.out.println("Enter first num");
int num1=scanner.nextInt();
System.out.println("Enter second num");
int num2=scanner.nextInt();
System.out.println("Enter third num");
int num3=scanner.nextInt();
System.out.println("Enter fourth num");
int num4=scanner.nextInt();
int sum=num1+num2+num3+num4;
int average=(num1+num2+num3+num4)/4;
int product=num1*num2*num3*num4;
System.out.println("Sum is"+sum);
System.out.println("Average is"+average);
System.out.println("Product is"+product);
}
9-Solve a program that inputs age in years and displays age in days and months.

import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner= new Scanner(System.in);
System.out.println("Enter Age in years");
int years=scanner.nextInt();
int months=years*12;
int days=years*365;

System.out.println(" Age in months equal to "+months );


System.out.println("Age in days equal to"+days);

}
}
10-Develop a program that inputs petrol in litres and displays how much distance the car
can cover using the available petrol. A car can travel 1 miles in 1 litre.

import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
System.out.println("petrol in liters");
double petrol=scanner.nextDouble();
double distance=petrol*1;
System.out.println("distance covered is"+distance+"in given petrol");

}
}
11-Construct a program that inputs total number of student in a class and fee per student.
It displays total fee collected from the class

import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Total number of students in class");
int students = scanner.nextInt();
System.out.println("Fee per student");
double fees = scanner.nextInt();
double totalfees=students*fees;
System.out.println("total fee is: "+totalfees);

}
}
12-Construct a program that inputs total number of student in a class and fee per student. It
displays total fee collected from the class.

import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
System.out.print("Enter the temperature in Fahrenheit: ");
double fahrenheit = scanner.nextDouble();
double celsius = (fahrenheit - 32) * 5 / 9;
System.out.println("temperture in celsius: " +celsius);

}
}
13-Develop a program that inputs five-digit number through the keyboard and calculates the
sum of its digits.

import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
System.out.print("Enter a five-digit number: ");
int number = scanner.nextInt();
if (number < 10000 || number > 99999) {
System.out.println("Please enter a valid five-digit number.");
} else {
int digit1 = number / 10000;
int digit2 = (number / 1000) % 10;
int digit3 = (number / 100) % 10;
int digit4 = (number / 10) % 10;
int digit5 = number % 10;

int sum = digit1 + digit2 + digit3 + digit4 + digit5;


System.out.println("SUM IS: "+sum);
}
}
}
14-Construct a program that inputs marks obtained by a student in five subjects. It then
calculates and displays the total marks and percentage.
import java.util.Scanner;s
public class Main {
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
System.out.println("MARKS OF SUBJECT 1:");
int subject1=scanner.nextInt();
System.out.println("MARKS OF SUBJECT 2:");
int subject2=scanner.nextInt();
System.out.println("MARKS OF SUBJECT 3:");
int subject3=scanner.nextInt();
System.out.println("MARKS OF SUBJECT 4:");
int subject4=scanner.nextInt();
System.out.println("MARKS OF SUBJECT 5:");
int subject5=scanner.nextInt();
int totalmarks=subject1+subject2+subject3+subject4+subject5;
double percentage=totalmarks/5.0;
System.out.println("Total Marks: " + totalmarks);
System.out.println("Percentage: "+ percentage);
}
}

You might also like