Computers Assignment 1
Computers Assignment 1
COMPUTER APPLICATIONS
ASSIGNMENT 1
2022-23
TERM 1
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) 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.
/* 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;
}
}
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]