Posts

Showing posts with the label Practice Sets

Java Practice Set 4

Image
 Java Practice Set 4 QUESTIONS --- SOLUTIONS/CODE --- package com.company ; import java.util.Scanner ; public class PS4 { public static void main (String[] args) { /* Q1 - What will be the output of this program: int a = 10; if (a=11){ System.out.println("I am 11"); } else{ System.out.println("I am not 11"); } ANSWER - This will simply throw an error because, in if statement, we used '=' as an assignment operator to run the program correctly, we should have use a logical operator '==' */ /* Q2 - Write a program to find out to whether a student is pass or fail; To pass it requires 40% of total marks and 33% marks of each subjects Assume 3 subjects and take marks as an input from the user */ byte s1 , s2 , s3 ; Scanner sc = new Scanner(System. in ) ; System. out .println( "Enter your marks in Physics"...

Java Practice Set 3

Image
 Java Practice Set 3 QUESTIONS -  SOLUTIONS/CODE ---  package com.company ; public class PS3 { public static void main (String[] args) { // Q1 - Write a JAVA program to covert a string to lowercase String str = "String" ; str = str.toLowerCase() ; System. out .println(str) ; // Q2 - Write a JAVA program to replace spaces with underscore String text = "Write a JAVA program to replace spaces with underscore" ; text = text.replaceAll( " " , "_" ) ; System. out .println(text) ; /* Q3 - Write a JAVA program to fill in a template which looks like below template = "Dear<|name|>, Thanks a lot" Replace 'name' with someone's name*/ String template = "Dear <|name|>, Thanks a lot" ; template = template.replace( "<|name|>" , "Saswata" ) ; System. out .println(template) ; // Q4 - Write a JAVA progr...

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 =...

JAVA Practice Set 1

JAVA Practice Set 1 Questions: Q1:    Write a program to sum three numbers in JAVA. Q2:    Write a program to calculate CGPA using marks of three subjects. Q3:    Write a JAVA program which asks the user to enter his/her name and greets them with "Hello                             <name> have a good day!" txt. Q4:    Write a JAVA program to calculate Kilometers to Miles. Q5:    Write a JAVA program to detect whether a number entered by the user is integer or not. Solutions:  package com.company ; import javax.swing.plaf.synth.SynthOptionPaneUI ; import java.util.Scanner ; public class PS1 { public static void main(String[] args) { // QUESTION 1 System.out.println( "Question 1" ) ; System.out.println( "Sum of Three Numbers" ) ; int a = 10 ; int b = 20 ; int c = 30 ; int sum = a+b+c ; ...