You are on page 1of 12

HIRANANDANI FOUNDATION SCHOOL, THANE

COMPUTER APPLICATIONS
ASSIGNMENT 1

2022-23
TERM 1

Name: Trisha Thakkar


Class/Div: IX- B
Roll No: 13
INDEX
Q. QUESTION PG.
NO. NO.

1. Write Java Expression 2

2. Purpose and return data type of the given Math functions 3

3. Evaluate the given expressions 4


4. Give the output of the following statements 5

5. Explain the following terms 6


6. Program to convert time into hours, minutes and seconds 7
7. Program to input the distance covered and calculate the amount 8-9
paid by the passenger
8. Program to input a year and check whether it is a leap year or 10
not.

Teacher’s Signature: _____________________________________


Question 1
Write Java expression for the following
i) a² + ab - b²
Ans) a*a + a*b – b*b

ii) 5x³+2yx+y
Ans) 5*x*x*x + 2*y*x + y

iii) x3 + y3 – xy/z
Ans) x*x*x + y*y*y – x*y/z
Question 2
State the purpose and return data type of the following functions.
i) Math.abs()
Ans) It always returns the absolute value of an argument. The return data type
could be int/long/double depending upon the input arguments.

ii) Math.max()
Ans) It returns the greatest value of the two given arguments. The return data type
may be int/long/double depending upon the input arguments.

iii) Math.ceil()
Ans) It returns the next higher integer number that is greater than or equal to the
argument. The return data type is double.
Question 3
Evaluate the following expressions.
i) c = a + b + a++ + b++ + ++a + ++b;
when a=11 and b=22
Ans) c= 11 + 22 + 11 + 22 + 13 + 24;
c= 103

ii) k = ++i * 7 + 2 - j--;


when i = and j = 21

iii) c= a + (--b + a++ % 2)


when a = 5 and b = 2
c= 5 + (1 + 5%2)
c=5+ (1+1)
c= 5+2
c= 7
Question 4
Give the output of the following
i) String y = (a % 2 == 0)? “Even” : “Odd”;
System.out.println(y);
when a = 10
Ans) Even

ii) Math. Floor(Math.max(3.4, 2.8));


Ans) 3.0

iii) int a = (b > 0) ? 1 : 0;


System.out.println(a);
when b = 5
Ans)
Question 5
Explain the following
i) Byte Code
Ans) Java compiler converts source code to an intermediate binary code. This code
helps generate machine code and is known as byte code.

ii) Tokens
Token is a set of valid characters used for writing a statement in Java program. In
other words, we may say a Java program consists of a number of tokens.

iii) Type Conversion in Java


If various types of data are used in an expression, a question obviously comes to
your mind what type of data it will return after execution. The system converts the
result into a specific data type known as Type Conversion.
Question 6
Write a program to input the time in seconds. Display the time after converting
them into hours, minutes and seconds.
Sample Input: Time in seconds 5420 Sample Output: 1 Hour 30 Minutes 20
Seconds

/* A program to accept the time in seconds and display the time after converting it
into hours, minutes and seconds*/

import java.util.Scanner;
public class Time
{
public static void main()
{
Scanner sc = new Scanner(System.in);
//Accepting the time in seconds
System.out.println(“Time in seconds”);
int input = sc.nextInt();
//Converting the time into hours, minutes and seconds
int h= input / 3600
int m= (input%3600)/ 60;
int s= (input%3600) %60;
System.out.println(“ h + “ Hours ” + m + “ Minutes ” + s + “ Seconds ”);
}
}
Question 7
Write a program to input the distance covered and calculate the amount paid by the
passenger. The program displays the printed bill with the details given below:
Taxi No. :
Distance covered :
Amount :

/* A program to input the distance covered and calculate the amount paid by the
passenger. The program displays the printed bill with the details given below:
Taxi No. :
Distance covered:
Amount :
*/
import java.util.Scanner;
public class Taxi
{
public static void main()
{
Scanner sc= new Scanner (System.in);
System.out.print("Enter Taxi Number: ");
String taxiNo = sc.nextLine();
//Accepting the distance travelled
System.out.print("Enter distance travelled: ");
double dist = sc.nextInt();
//Calculating the fare
int fare = 0;
if (dist <= 5)
fare = 100;
else if (dist <= 15)
fare = 100 + (dist - 5) * 10;
else if (dist <= 25)
fare = 100 + 100 + (dist - 15) * 8;
else
fare = 100 + 100 + 80 + (dist - 25) * 5;

System.out.println("Taxi No: " + taxiNo);


System.out.println("Distance covered: " + dist);
System.out.println("Amount: " + fare);

}
}
Question 8
Write a program to input a year and check whether it is a leap year or not.
[Hint: A year is leap if it is divisible by 4 and 400, but not by 100]

/* A program to input a year and check whether it is a leap year or not.*/


import java.util.Scanner;
public class leapyear;
{
public static void main()
{
Scanner sc= new Scanner (System.in);
//Accepting the year
System.out.println(“Enter the year”);
int year = sc.nextInt();
//Calculating whether the year is a leap year
if (year % 400 == 0)
System.out.println(year + " is a leap year.");
else if (year % 100 == 0)
System.out.println(year + " is not a leap year.");
else if (year % 4 == 0)
System.out.println(year + " is a leap year.");
else
System.out.println(year + " is not a leap year.");
}

You might also like