/Java_Questions

Find Important Questions From The Beginning

Primary LanguageJava

Java_Questions

Find Important Questions From The Beginning

In Day1 Questions

Q1) Explain Type casting and its types with examples?

Q2) Create a class Main with a main method. This main method has one local variable: city : String

if city.equals("Mumbai") then print "Financial city" if city.equals("Kolkata") then print "City of Joy" if city.equals("Delhi") then print "Capital of the country" if city.equals("Bangalore") then print "Cyber City" otherwise "May be Other Indian City"

● You should implement this using switch-case

Q3) Explain the difference between local and instance variables?


In Day 2 Questions

Q1) The set of positive numbers starting from 1 is known as Natural Numbers. The sum of the first N natural numbers is given by the formula [N * (N + 1)] / 2 For example, given a number 5, the sum of the first 5 natural numbers will be[5 * (6)]/2 = 15 ● Write a Java class with a static method that will take a number as a parameter, and print the sum of the natural number from 1 to the number supplied as the method argument. ● Call the above-defined method from the main method of that class by supplying any number as an argument and print the result.

Q2) The prime factors of a number are all of the integers below that number that are divisible into the number as well as 1. For example, the prime factors of 12 are 1,2,3,4,6, and 12. ● Write a Java class with a static method that will take a number and print all the prime factorial of that number. ● The Supplied number should be between 2 and 100. otherwise, it should print “Invalid number”. ● Call this method from the main method by supplying any valid argument.

Q3) Define Wrapper Classes in Java.