0% found this document useful (0 votes)
48 views4 pages

Double, and Float Variable Types Are Different in The Way That They Store The Values 2

This document contains 5 questions with multiple parts each that relate to Java programming concepts. Question 1 covers topics like type conversion, error types, arithmetic expressions, and output. Question 2 gives examples of arithmetic expressions and logical expressions to evaluate. Question 3 covers data types, arithmetic expressions, classes, and output. Question 4 gives examples of unary and binary operators, operator precedence, and input/output methods. Question 5 provides two code snippets, the first rearranges the digits of a 6 digit number, the second adds a character and number input.

Uploaded by

George Mathew
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)
48 views4 pages

Double, and Float Variable Types Are Different in The Way That They Store The Values 2

This document contains 5 questions with multiple parts each that relate to Java programming concepts. Question 1 covers topics like type conversion, error types, arithmetic expressions, and output. Question 2 gives examples of arithmetic expressions and logical expressions to evaluate. Question 3 covers data types, arithmetic expressions, classes, and output. Question 4 gives examples of unary and binary operators, operator precedence, and input/output methods. Question 5 provides two code snippets, the first rearranges the digits of a 6 digit number, the second adds a character and number input.

Uploaded by

George Mathew
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/ 4

QUESTION 1

A) I) EXPLICIT TYPE CONVERSION


II) Implicit conversion

B) I) Runtime error
ii) Semantic error

C) (a*a + b*b + c*c) /(2*b*c*c)

D) I) 0.75

ii) Marks: 83.5

Question 2

A) -49
B) 104
C) false
D) D
E) -21.09

Question 3

a) Long data type


Character data type
b) 1. Double, and Float variable types are different in the way that they store the values.
2. The sum of410

c) class project
{
public static void main()
{
double m = 3.0;
double n = 0.142;
System.out.println(m+n); // I have written an output line just for testing

}
}
d) double a=45.1;
double b=15.05;
double c= 92, sum=0;
sum=(a+b*c/2);
System.out.println("The answer =" +sum);

Question 4

a) i) c*=10
ii)t%=15
b) A unary operator requires one operant wheras a binary operand requires two operands
example -6 is a unary operator but a binary operator would be -6-5.
c) False
d) Operator precedence means the grouping of terms in an expression. Example in an
expression the multiplication operator has a higher precedence than a subtraction operator.
Operator precedence decides how an expression is to be evaluated.
e) I)sc.nextInt();
ii)sc.next(); or sc.nextLine();

Question 5
1)
Okk
import java.util.*;
 
class Holiday1
{
    public static void main()
    {
        Scanner sc= new Scanner(System.in);
        System.out.println("Enter a six digit number that is not a multiple of 10, 100 or 1000");
        int num= sc.nextInt();
        int c1, c2, c3, c4, c5, c6; //Variables used to store each of the 6 digits
        int bal= num;
        if(num>99999 && num<1000000)
        {
            if(num%10==0 || num%100==0 || num%1000==0)
            {
                System.out.println("Invalid Input");
            }
            else
            {
                c1= num/100000;
                bal= (int)bal%100000;
                c2= bal/10000; // George Christian Mathew 9 H
                bal= (int)bal%10000;
                c3= bal/1000;
                bal= (int)bal%1000;
                c4= bal/100;
                bal= (int)bal%100;
                c5= bal/10;
                bal= (int)bal%10;
                c6= bal;
                int new_n= (c3*100000)+(c1*10000)+(c6*1000)+(c4*100)+(c2*10)+c5;
                System.out.println(new_n);
            }
        }
        else
        {
            System.out.println("Invalid Input");
        }
    }
}
2) import java.util.*;
class holiday2
{
public static void main()
{
Scanner sc = new Scanner(System.in);
System.out.println("Please enter a character");
char c =sc.next().charAt(0);
System.out.println("Please enter a number between 1 and 13");

int a =sc.nextInt(); // gEORGE CHRISTIAN MATHEW 9H

if(a <=13 && a>=1)


{
c+=a;
System.out.println("The number plus the letter equals :" + c);
}
else
{
System.out.println("Invalid Input");
}
}
}

You might also like