Double, and Float Variable Types Are Different in The Way That They Store The Values 2
Double, and Float Variable Types Are Different in The Way That They Store The Values 2
B) I) Runtime error
ii) Semantic error
D) I) 0.75
Question 2
A) -49
B) 104
C) false
D) D
E) -21.09
Question 3
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");