You are on page 1of 6

Programming Fundamentals

Lecture # 3
By
Imran Kazmi
Assignment
Solutions of the given assignment

• P-1) The distance between two cities is input through the keyboard(in km). Write
a program to convert the distance in meters, feet, inches and centimeters.

• P-2) Interchange the contents of two variables without introducing third variable.

• P-3) if a five digit number is input through the keyboard, write a program to
calculate the sum of its digits.

• P-4) if the selling price of an item is input through the keyboard and the profit
earned on it is also input through the keyboard. Write a program to find the cost
price of the item .
Data Types in Java
• Int : 4 bytes
• Long: 8 bytes
• Short: 2 bytes
• Byte: 1 byte
• Float : 4bytes
• Double: 8 bytes
write down the program that simply add two integer
values
• public class sum {

• public static void main(String[] args)


• {

• int a,b,c;

• System.out.println("first value");
• a=10;
• System.out.println("second value");
• b=20;

• c=a+b;
• System.out.println("sum="+c);

• }

• }
Write down the program that calculate the sum of 3 numbers and display the average of these numbers.

• public class sajjad{


• public static void main(String[] args)
• {

• float a,b,c,d,avg;

• a=10;
• b=20;
• c=30;
• d=a+b+c;
• avg=d/3;
• System.out.println("sum="+d);
• System.out.println("average"+avg);

• }

• }
Write down the program which input three numbers from the user and display the
sum and average of three numbers

• import java.io.*;
• public class sajjad{
• public static void main(String[] args)throws Exception
•{
• Int a,b,c,d,avg;
• BufferedReader str=new BufferedReader(new InputStreamReader(System.in));

• String s;
• System.out.println("enter first value");
• s =str.readLine();
• a=Integer.parseInt(s);
• System.out.println("enter second value");
• s=str.readLine();
• b=Integer.parseInt(s);
• System.out.println("enter third value");
• s=str.readLine();
• c=Integer.parseInt(s);
• d=a+b+c;
• avg=d/3;
• System.out.println("sum="+d);
• System.out.println("average"+avg);

•}
}

You might also like