Skip to content

KUSHALDBSSRM/AssignmentControlStatements

Repository files navigation

AssignmentControlStatements

Array Assignment Questions based on Programming (ArrayAssignment1,...)

  1. Write a program to find the largest and smallest element in the given array?
  2. Given an array A[], write a program to check whether the element "x" present in the array or not?
  3. Given an array A[], write a program to sort the array?
  4. Given an array A[], write a program to print the numbers which are occuring odd number of times?
  5. Write a program to find the missing number in integer array of 1 to 100?
  6. Write a program to find duplicate element element in an integer array?
  7. Write a program to reverse the given array?
  8. Write a program to find third smallest element in the given array?
  9. Can you change size of array once created?
  10. Can you store String in an array of Integer in Java? compile time error or runtime exception?

String Assignment Questions based on Programming

  1. Write a Java program that counts vowels in a string?

  2. PALINDROME: Write a program that takes an English word and test whether or not this word is a palindrome. (e.g. a word that reads the same both forwards and backwards such as “level”).

  3. Write a java program to reverse a string without using reverse() method?

  4. Given a string s1 and a string s2, write a java method to say whether s2 is a rotation of s1 ? Example : given s1 = abcd and s2 = cdab, return true, given s1 = abcd, and s2 = acbd , return false

  5. Write a java program to remove characters from the first string which are present in the second string?

  6. Write a java program to print all the duplicate characteres in the given string?

  7. Write a java program to find the most repeted character in the given string?

  8. Write a java program to reverse a words in a given string? Example : i love raudra and ravindra ravindra and raudra love i

  9. Given a string, find its first non-repeating character? Example : Given String : ravindra Output : v

  10. Write a java program to sort the given string? Example: input : ravindra output : aadinrrv

Operators Assignment Questions

Q1: (Convert Celsius to Fahrenheit) Write a program that reads a Celsius degree in a double value from the console, then converts it to Fahrenheit and displays the result. The formula for the conversion is as follows: fahrenheit = (9 / 5) * celsius + 32 Q2: (Compute the volume of a cylinder) Write a program that reads in the radius and length of a cylinder and computes the area and volume using the following formulas: area = radius * radius * pi volume = area * length

Q3. (Financial application: calculate tips) Write a program that reads the subtotal and the gratuity rate, then computes the gratuity and total. For example, if the user enters 10 for subtotal and 15% for gratuity rate, the program displays $1.5 as gratuity and $11.5 as total.

Q4. (Sum the digits in an integer) Write a program that reads an integer between 0 and 1000 and adds all the digits in the integer. For example, if an integer is 932, the sum of all its digits is 14. Hint: Use the % operator to extract digits, and use the / operator to remove the extracted digit. For instance, 932 % 10 = 2 and 932 / 10 = 93

Q5. (Find the number of years) Write a program that prompts the user to enter the minutes (e.g., 1 billion), and displays the number of years and days for the minutes. For simplicity, assume a year has 365 days.

Q6: (Health application: computing BMI) Body Mass Index (BMI) is a measure of health on weight. It can be calculated by taking your weight in kilograms and dividing by the square of your height in meters. Write a program that prompts the user to enter a weight in pounds and height in inches and displays the BMI. Note that one pound is 0.45359237 kilograms and one inch is 0.0254 meters.

Q7. (Geometry: distance of two points) Write a program that prompts the user to enter two points (x1, y1) and (x2, y2) and displays their distance between them.

Q8: (Print a table) Write a program that displays the following table. Cast floatingpoint numbers into integers. a b pow(a, b) 1 2 1 2 3 8 3 4 81 4 5 1024 5 6 15625s

Control Statements Assignment 1

  1. Write a program to find sum of two numbers?
  2. Write a program to find given number is odd or even?
  3. Write a java program to swap two variables?
  4. Write a program to Swap two numbers without using third variable?
  5. Write a program to check the given number is prime or not?

Control Statements Assignment 2 (Programs 2a, 2b,...)

  1. Write a program to find factorial? Description: Factorial of any number is the product of an integer and all the integers below it for example factorial of 4 is 4! = 4 * 3 * 2 * 1 = 24.

  2. Write a program to reverse number? Description : Reverse number means reverse the position of all digits of any number. For example reverse of 839 is 938. Hint: For this program you need modulus operator concept and while loop, while loop is used for check condition and modulus used for find the remainder.

  3. Write a program to print Fibonacci Series? Description : Fibonacci series is in the form of 0, 1, 1, 2, 3, 5, 8, 13, 21,...... Hint: To find this series we add two previous terms/digits and get next term/number

4.Write a program to check given number is Armstrong number or not? Description: Armstrong number is a number that is the sum of its own digits each raised to the power of the number of digits is equal to the number itself. For example:  Three Digits Armstrong number is 153, 1 ^ 3 + 5 ^ 3 + 3 ^ 3 = 153  Four Digits Armstrong number is 1634, 1 ^ 4 + 6 ^ 4 + 3 ^ 4 + 4 ^ 4 + = 1634

  1. Write a program to Find Largest Number Among Three Numbers Input three number from user and compare these number with each others and find largest number among these three numbers.

Control Statements Assignment 3 (Programs 3a, 3b ,....)

  1. Find largest number among three numbers using ternary operator?

  2. Write a program to check the given number is palindrome or not? Descritpion : A Palindrome number is a number that remains the same when its digits are reversed. Like 16461, for example: we take 121 and reverse it, after revers it is same as original number.

  3. Write a program to print star pattern? Input n= 5; Output:
    * * *




  4. Write a program to print following pattern? Input : n = 5 Output:



* * * * *
  * * * 
    * 
  1. Write a program to print following pattern? Enter nubmer of rows: 5

       *
     * * *
    



* * * * * * *
  * * * * *
    * * *
      *

Object Orientation 2 Assignment

  1. How do you implement multiple inheritance in java?
  2. How do you restrict a member of a class from inheriting to it’s sub classes.?
  3. Are constructors and initializers also inherited to sub classes.?
  4. Are static members inherited to sub classes?
  5. Can we use a field or a method declared without access modifiers outside the package.?
  6. Can a top level class be private or protected?

Constructor Assignment 1

  1. What is the output of the following program? package main; class Parent { public void display() { System.out.println("Parent"); }
    } class Child extends Parent {
    public void display() { System.out.println("Derived"); } } class Main{ public static void doDisplay( Parent o ) { o.display();
    }

    public static void main(String[] args) { Parent x = new Parent(); Parent y = new Child(); Child z = new Child(); doDisplay(x); doDisplay(y); doDisplay(z); } }

  2. What is the output of following program? class Coordinate { int x, y;

    public Coordinate(int x, int y) { this.x = x; this.y = y; } } public class Main { public static void main(String args[]) { Coordinate p = new Coordinate(); System.out.println("x = " + p.x + ", y = " + p.y); } }

  3. What is the output of following program? public class Test {
    int x = 2; Test(int i) { x = i; } public static void main(String[] args) {
    Test t = new Test(5); System.out.println("x = " + t.x); } }

  4. What is the output of following program? class SuperClass { protected void foo() {} } class Child extends SuperClass { void foo() {} } public class Test { public static void main(String args[]) { Child child = new Child(); child.foo(); } }

  5. What is the output of the following program? public class Test { public static void test(String s) { System.out.println("In String"); } public static void test(Object o) { System.out.println("In Object"); }

    public static void main(String args[]) { test(null); } }

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages