import java.util.*;
import java.lang.*;
import java.io.*;
// The main method must be in a class named "Main".
class Main {
public static void main(String[] args) {
// System.out.println("Hello world!");
// int a = 10;
// int b = 10;
// System.out.println(a>=b);
// Day 8 - Beginner: Operators (Arithmetic, Assignment, Relational, Logical, Unar.y)
//----------------------------------------------
// Q1. Problem Description
// Your younger brother is going to a modern school. In his school, there was a coding competition planned.
// The pannel asked a question
// "Write a program which can perform the task - Add two numbers and divide them by a third number and print the remainder".
// You are a programmer and your brother asks you to write a code that helps him to check his approach.
// ANSWER
// Scanner scn = new Scanner(System.in);
// int N1 = scn.nextInt();
// int N2 = scn.nextInt();
// int N3 = scn.nextInt();
// int y = N1 + N2;
// int x = y%N3;
// System.out.println(x);
//----------------------------------------------
// Q2. Logical Printing
// Take three numbers from the user, i.e. n1, n2 and n3.
// Now your target is Print the output in the following ways:
// In the first line: print "Number 1 is " then n1
// In the second line: print "Number 2 is " then n2
// In the third line: print "Number 3 is " then n3
// In the fourth line: print "(n1 < n2) condition is " then print boolean result of (n1 < n2).
// In the fifth line: print "(n2 == n3) condition is " then print boolean result of (n2 == n3).
// In the sixth line: print "(n1 < n2) && (n2 == n3) condition is " then print boolean result of (n1 < n2) && (n2 == n3).
// ANSWER
// Scanner scn = new Scanner(System.in);
// int n1 = scn.nextInt();
// int n2 = scn.nextInt();
// int n3 = scn.nextInt();
// boolean x = (n1 < n2);
// boolean y = (n2 == n3);
// boolean z = (n1 < n2) && (n2==n3);
// System.out.println("Number 1 is " + n1);
// System.out.println("Number 2 is " + n2);
// System.out.println("Number 3 is " + n3);
// System.out.println("(n1 < n2) condition is " + x);
// System.out.println("(n2 == n3) condition is " + y);
// System.out.println("(n1 < n2) && (n2 == n3) condition is " + z);
//----------------------------------------------
// Q3. Operator Printing ~~ Problem Description :
// Take three numbers from user, i.e. n1, n2 and n3.
// Now your target is Print the output in following ways:
// In first line : print "Number 1 is " then n1
// In second line : print "Number 2 is " then n2
// In third line : print "Number 3 is " then n3
// In fourth line : print "(n1 > n2) condition is " then print boolean result of (n1 > n2).
// In fifth line : print "(n2 <= n3) condition is " then print boolean result of (n2 <= n3).
// In sixth line : print "(n1 < n2) || ((n2 == n3) && (n1 < n3)) condition is " then print boolean result of (n1 < n2) || ((n2 == n3) && (n1 < n3)).
// ANSWER
// Scanner scn = new Scanner(System.in);
// int n1 = scn.nextInt();
// int n2 = scn.nextInt();
// int n3 = scn.nextInt();
// boolean x = (n1 > n2);
// boolean y = (n2 <= n3);
// boolean z = (n1 < n2) || ((n2 == n3) && (n1 < n3));
// System.out.println("Number 1 is " + n1);
// System.out.println("Number 2 is " + n2);
// System.out.println("Number 3 is " + n3);
// System.out.println("(n1 > n2) condition is " + x);
// System.out.println("(n2 <= n3) condition is " + y);
// System.out.println("(n1 < n2) || ((n2 == n3) && (n1 < n3)) condition is " + z);
//----------------------------------------------
// Q4. Check If All Conditions are True: Problem Description
// Take three numbers from user, i.e. n1, n2 and n3.
// You have to print numbers taken by user as :
// In First Line : "Number 1 is " then n1.
// In Second Line : "Number 2 is " then n2.
// In Third Line : "Number 3 is " then n3.
// then In Fourth Line print "true", if all the conditions is true from the following:
// Condition 1 : n1 < 50
// Condition 2 : n2 > n3
// Condition 3 : n1 <= n3
// Otherwise print false.
// ANSWER
// Scanner scn = new Scanner(System.in);
// int n1 = scn.nextInt();
// int n2 = scn.nextInt();
// int n3 = scn.nextInt();
// System.out.println("Number 1 is " + n1);
// System.out.println("Number 2 is " + n2);
// System.out.println("Number 3 is " + n3);
// System.out.println((n1<50) && (n2>n3) && (n1<n3));
//----------------------------------------------
// Q5. Session 3 MCQ.
// int a = 2 - (-7);
// System.out.println(a);
//ANSWER (9)
//----------------------------------------------
// Q6. Session 3 MCQ E
// What is the output of the Java code snippet?
// boolean b = false;
// b = !b;
// System.out.println(b);
// ANSWER : TRUE
//----------------------------------------------
// Q7. What is the output of the Java code snippet?
// int a=3, b=8;
// boolean c = a > 5 && ++b > 6;
// System.out.println(b);
// ANSWER : 8;
// int a=3, b=8;
// boolean c = a < 5 || --b > 7;
// System.out.println(c);
// System.out.println(++b);
// int a=3, b=8;
// --b;
// b= ++b + 1;
// System.out.println(b);
//----------------------------------------------
// Q8. Session 2 MCQ J
// What is the output of the JAVA code snippet?
// int a = 5, b = 10, c = 15;
// a -= 3;
// b *= 2;
// c /= 5;
// System.out.println(a + " " + b + " " + c);
// ANSWER:
// 2 20 3 - CORRECT ANSWER
// 2 20 5
// 2 10 5
// -2 20 3
//----------------------------------------------
// Q9. Session 3 MCQ I
// Raw Problem
// What is the output of the following program :
// int a = 20;
// int b = 10;
// System.out. print((a > b) && (b++ > 25));
// System.out.println(b);
// ANSWER:
// true 10
// true 11
// false 10
// false 11 - CORRECT ANSWER
//----------------------------------------------
// Q10. Session 3 MCQ J
// What is the correct shorthand way to multiply the value present in variable x by 2 ?
// x ** 2
// x = x * 2
// x *= 2
// None of the above
// ANSWER: X * = 2;
//----------------------------------------------
// Q11. Check If One Condition is True
// Problem Description:
// Take three numbers from user, i.e. n1, n2 and n3.
// You have to print numbers taken by user as :
// In First Line : "Number 1 is " then n1.
// In Second Line : "Number 2 is " then n2.
// In Third Line : "Number 3 is " then n3.
// then In Fourth Line print "true", if atleast single condition is true from the following:
// Condition 1 : n1 < 50
// Condition 2 : n2 > n3
// Condition 3 : n1 == n3
// Otherwise print false.
// Note : This Question is based on learning of logical operators, try to solve this problem without "if-else".
// Scanner scn = new Scanner(System.in);
// int n1 = scn.nextInt();
// int n2 = scn.nextInt();
// int n3 = scn.nextInt();
// Boolean b1 = (n1 < 50) || (n2 > n3) || (n1 == n3);
// System.out.println("Number 1 is " + n1);
// System.out.println("Number 2 is " + n2);
// System.out.println("Number 3 is " + n3);
// System.out.println(b1);
// Additional Problems
//----------------------------------------------
// Q1. Q1. Print-Message
// Problem Description
// Write a program to take two inputs from the user ,
// first is String (S) and second is an Integer (N) and then print the desired output.
// Desired output is - Print Integer value followed by the String value in the same line.
// Input Format: First Line is S the value of String, Second Line is N the value of integer variable.
// Output Format: Print Integer value followed by the String value in the same line.
// ANSWER:
// Scanner scn = new Scanner(System.in);
// String S = scn.nextLine();
// int N = scn.nextInt();
// System.out.print(N + " ");
// System.out.print(S);
//----------------------------------------------
// Q2. Count-Apples - Problem Description:
// Rahul has N Apples initially, Karan has M apples initially.
// Rahul gave 5 apples to Karan and after some time Rahul plucked 2 times Initial apples (N) he had from Tree.
// Find out the total number of apples Rahul and Karan are left with.
// Input Format: First Line is N the initial number of apples Rahul has.
// Second Line is M the initial number of apples Karan has.
// Output Format: Print the total number of Apples Rahul & Karan has separated by a space.
// ANSWER
// Scanner scn = new Scanner(System.in);
// int Rahul = scn.nextInt();
// int Karan = scn.nextInt();
// int Rahul1 = (Rahul-5) + (2*Rahul);
// int Karan1 = (Karan + 5);
// System.out.println(Rahul1 + " " + Karan1);
//----------------------------------------------
// Q3. Find New Volume: Problem Description
// Given an integer A, find the volume of a cube with side (A+1).
// Note : Try to use shorthand increments for learning purposes.
// Input Format: The value of A
// Output Format: Print the volume of the new cube.
//ANSWER
// Scanner scn = new Scanner(System.in);
// int A = scn.nextInt();
// // A = ++A // This is a short-hand notation method.
// int vol = A + 1;
// vol = vol*vol*vol;
// System.out.println(vol);
//----------------------------------------------
// Q4. Modify-X : Problem Description
// You are given a variable X, modify it using the following steps.
// Make X five times greater than the original value.
// Increment the value of X by 10.
// Divide the value of X by 2.
// Note : Do modification in X step by step without using any extra variable.
// The value of X must be modified at the end of all steps.
// Do not use any extra variable other than X.
// Input Format: The value of variable X.
// Output Format : Print the modified value of variable X.
//ANSWER
// Scanner scn = new Scanner(System.in);
// int X = scn.nextInt();
// X *= 5;
// X += 10;
// X /= 2;
// System.out.println(X);
//----------------------------------------------
// Q5. Session 3 MCQ L : What is the significance of using the "!” symbol in JAVA?
// It denotes factorial
// It denotes Not - CORRECT ANSWER
// Both factorial and Not
// Invalid Symbol
//----------------------------------------------
// Q6. Session 3 MCQ O: What will be the output for the following program?
// System.out. println(1 + 1 + 1 + 1 + 1 == 5);
// ANSWER :
// true - CORRECT ANSWER
// false
// Compilation Error
// None of these
//----------------------------------------------
// Q7. Session 3 MCQ P: Which of the following statements are true?
// 1. x++ and ++x both are the same.
// 2. x++ executes the statement and then increments the value.
++x increments the value and then executes the statement. -- CORRECT ANSWER
// 3. ++x has higher precedence than x++
// 4. None of the above
//----------------------------------------------
Q8. Session 3 MCQ Q:
// int a, b, c, d;
// a = b = c = d = 20;
// a += b -= c *= d /= 20;
// System.out. println(“A = ” + a + “ B = ” + b + “ C = ” + c + “ D = ” + d);
// Compile time error
// Run time error
// A = 20 B = 0 C = 20 D = 1 - CORRECT ANSWER
// None of the mentioned
// a += b -= c *= d /= 20; // d=20/20= 1; c=20*1 = 20;
// a += b -= c *= d /= 20; // b=b(20)-c(20) = 0; a = a(20)+b(0) = 20;
// answer: a = 20, b = 0, c=20, d= 1;
//----------------------------------------------
// Q9. Session 3 MCQ R:
// Which of the following statements are true?
// 1. next() can read the input only till the space. It can't read two words separated by a space.
// 2. nextLine() reads input including space between the words i.e it reads till the end of line.
// 3. Java is a strictly typed language.
// 4. All of the Above
// CORRECT ANSWER - 4
//----------------------------------------------
// Q10. Session 3 MCQ S
// What happens to the second operand/expression if the first operand is FALSE with the AND (&&) operator?
// 1. Second Operand/Expression is evaluated and AND is applied.
// 2. Evaluation of Second Operand/Expression is Skipped. - CORRECT ANSWER
// 3. The Compiler starts taking more memory.
// 4. The Compiler starts taking more CPU power.
}
}
To embed this program on your website, copy the following code and paste it into your website's HTML: