Chapter 2- Practice Set (Java Practice Questions And Answers)


Questions :

1.  What will be the result of the following expression: 
float a = 7/4 * 9/2

2.  Write a java program to encrypt a grade by adding 8 to it. 
Decrypt it to show the correct grade.
Use comparison operators to find out whether a given number is greater than the user entered number or not.
Write the following expression in a java program:
v2-u2/2as

3.  Find the value of the following expression:
int x = 7
int a = 7*49/7 + 35/7
Value of a?

4.  Write the following expressions in java Program :
v2-u2/2as

5.  Find the value of following Expressions:
int x=7;
int a=7*49/7+35/7;
value of a?


Code Solution:


// Question -1 Answer

package com.company;

public class cwh_12_ps2_pr01 {
public static void main(String[] args) {
float a = 7/4.0f * 9/2.0f;
// float a=1.75*9/2;
// float a=15.75/2; (associativity left to right)
// float a=7.875;
System.out.println(a);
}
}
/*
7.875
*/


/*
float a=7/4*9/2; // float a=1*9/2; float a=9/2; float a=4;
System.out.println(a);

answer = 4
*/


// Question -2 Answer

package com.company;

public class cwh_12_ps2_pr02 {
public static void main(String[] args) {
char grade = 'B';
grade = (char)(grade + 8);
System.out.println(grade); // Output : J
// Decrypting the grade
grade = (char)(grade - 8);
System.out.println(grade); // Output : B
}
}


// Question 3- Answer

package com.company;
import java.util.Scanner;

public class cwh_12_ps2_pr_03 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
System.out.println(a>8);

}
}
/*
99
true

3
false

*/

// Question 4- Answer
package com.company;
import java.util.Scanner;
public class chapter2answer {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the value of v :");
float v=sc.nextFloat();
System.out.println("Enter the value of u");
float u=sc.nextFloat();
System.out.println("Enter the value of a");
float a=sc.nextFloat();
System.out.println("Enter the value of s");
float s=sc.nextFloat();
float ans=(v*v-u*u)/(2*a*s);
System.out.println(ans);

}
}

/*
Enter the value of v :
5
Enter the value of u
6
Enter the value of a
2
Enter the value of s
3
-0.9166667
*/


// Question 5- Answer
package com.company;
public class chapter2answer {
public static void main(String[] args) {
int a=7*49/7+35/7;
System.out.println(a);

}
}

/*
54
*/



Aryadeep

Welcome to CodeWithARYA. It's My Personal Reference Website. Where You Can Get Amazing Codes. Have a Look.

Post a Comment

Previous Post Next Post