JAVA Practice Set 2

JAVA Practice Set 2

QUESTIONS - 

Q1 - What will be the result of the following expression --- float f = 7/4 * 9/2. 
Q2 - Write a JAVA program to encrpyt a grade by adding 8 to it. Decrypt it to show correct 
        grade.
Q3 - Use Comparison Operators to find out whether a given number is greater than the user 
        entered number or not.
Q4 - Write the following expression in a JAVA program --- v^2-u^2/2as. 
Q5 - Find the value of the following expression --- int x = 7*49/7+35/7 . 

CODE -

package com.company;
import java.util.Scanner;
public class PS2 {
public static void main(String[] args) {
// Practice Set 2

/* Q1 - What will be the result of the following expression
float f = 7/4 * 9/2 */
float f = 7/4f * 9/2f;
System.out.println(f);

/* Q2 - Write a JAVA program to encrpyt a grade by adding 8 to it.
Decrypt it to show correct grade. */
char grade = 'B';
grade = (char)(grade+8); //Encrypting the grade
System.out.println(grade);
grade = (char)(grade-8); //Decrypting the grade
System.out.println(grade);

/* Q3 - Use Comparison Operators to find out whether a given number is greater
than the user entered number or not. */
System.out.println("Input the number ------");
Scanner inp = new Scanner(System.in);
int b = inp.nextInt();
System.out.println(b>8);

/* Q4 - Write the following expression in a JAVA program --- v^2-u^2/2as */
System.out.println("Input the values----");
float v = inp.nextFloat();
float u = inp.nextFloat();
float a = inp.nextFloat();
float s = inp.nextFloat();
float formula = (((v*v)-(u*u))/(2*a*s));
System.out.println(formula);

/* Q5 - Find the value of the following expression --- int x = 7*49/7+35/7 */
int x = 7*49/7+35/7;
System.out.println(x);
}
}

Comments

Popular posts from this blog

Java Practice Set 4

Introduction to Java + Installing Java JDK and IntelliJ IDEA for Java