Login


Lost your password?

Don't have an account ?
Register (It's FREE) ×
  


Shop

JAVA: Solved Problems
String class methods to separate file path, name and extension #7428 (18-Apr-2019)
In Topic(s) : String Class Functions   

Write a program to assign a full path and file name as given below. Using library functions, extract and output the file path, file name and
file extension separately as shown.
Input C:\Users\admin\Pictures\flower.jpg
Output Path: C:\Users\admin\Pictures\
File name: flower
Extension: jpg

Write a program to assign a full path and file name as given below. Using lib


Floyd’s Triangle and ICSE as pattern #7319 (16-Apr-2019)
In Topic(s) : Pattern Printing   

Using the switch statement, write a menu driven program for the following:
(i) To print the Floyd’s triangle
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
(ii) To display the following pattern
I
I C
I C S
I C S E
For an incorrect option, an appropriate error message should be displayed.

Using the switch statement, write a menu driven program for the following:


07A-2017 #7262 (15-Apr-2019)
In Topic(s) : Array Basics   

Write a program to input integer elements into an array of size 20 and perform the following operations:
(i) Display largest number from the array.
(ii) Display smallest number from the array.
(iii) Display sum of all the elements of the array.

Write a program to input integer elements into an array of size 20 and perfor


Series problems #7260 (15-Apr-2019)
In Topic(s) : Series Printing   

Using switch statement, write a menu driven program for the following:

(i) To find and display the sum of the series given below:
S = x1 – x2 + x3 – x4 + x5 … – x20, where x = 2.
(where x = 2)

(ii) To display the following series:
1 11 111 1111 11111
For an incorrect option, an appropriate error message should be displayed.

Using switch statement, write a menu driven program for the following:


Spy number check #7256 (15-Apr-2019)
In Topic(s) : Specially Named Numbers   

Write a program to accept a number and check and display whether it is a spy number or not. (A number is spy if the sum of its digits equals the product of its digits.)
Example: consider the number 1124, Sum of the digits = 1 + 1 + 2 + 4 = 8
Product of the digits = 1 x 1 x 2 x 4 = 8

Write a program to accept a number and check and display whether it is a spy


Class definition – Electric Bill #7253 (15-Apr-2019)
In Topic(s) : Defining Classes   

Define a class ElectricBill with the following specifications:

class : ElectricBill
Instance variables / data member:
String n – to store the name of the customer
int units – to store the number of units consumed
double bill – to store the amount to be paid
Member methods:
void accept( ) – to accept the name of the customer and number of units consumed
void calculate( ) – to calculate the bill as per the following tariff:
Number of units Rate per unit
First 100 units Rs.2.00
Next 200 units Rs.3.00
Above 300 units Rs.5.00
A surcharge of 2.5% charged if the number of units consumed is above 300 units.
void print ( ) – To print the details as follows:
Name of the customer: ………………………
Number of units consumed: ………………………
Bill amount: ………………………
Write a main method to create an object of the class and call the above member methods.

Define a class ElectricBill with the following specification


03J-2017 #7251 (15-Apr-2019)
In Topic(s) : Scanner Input   

What is the difference between the Scanner class functions next() and nextLine()?

What is the difference between the Scanner class functions next() and nextLin


Output writing and loop counting #7248 (15-Apr-2019)
In Topic(s) : Compound or Nested Loops   

Analyze the given program segment and answer the following questions:

for(int i=3;i<=4;i++ ) {
for(int j=2;j<i;j++ ) {
System.out.print(“” ); }
System.out.println(“WIN” ); }

(i) How many times does the inner loop execute?
(ii) Write the output of the program segment.

Analyze the given program segment and answer the following questions:


Output Writing – Using integer wrapper #7246 (15-Apr-2019)
In Topic(s) : Wrapper Classes   

Give the output of the following code:

String A =”26″, B=”100″;
String D=A+B+”200″;
int x= Integer.parseInt(A);
int y = Integer.parseInt(B);
int d = x+y;
System.out.println(“Result 1 = “+D);
System.out.println(“Result 2 = ” +d);

Give the output of the following code:

String A =”26″, B=&


Output based on Math functions #7244 (15-Apr-2019)
In Topic(s) : Math Functions   

What are the values stored in variables r1 and r2:
(i) double r1 = Math.abs(Math.min(-2.83, -5.83));
(ii) double r2 = Math.sqrt(Math.floor(16.3));

What are the values stored in variables r1 and r2:
(i) double r1 = Math


Output writing – indexOf, substring #7241 (15-Apr-2019)
In Topic(s) : String Class Functions   

Write the output for the following:
String s=”Today is Test” ;
System.out.println(s.indexOf(‘T’));
System.out.println(s.substring(0,7) + ” ” +”Holiday”);

Write the output for the following:
String s=”Today is Test”



Do while to for conversion #7237 (15-Apr-2019)
In Topic(s) : Basic Loop Types   

Convert following do-while loop into for loop.

int i=1;
int d=5;
do{
  d=d*2;
  System.out.println(d);
  i++;
}while(i<=5);

Convert following do-while loop into for loop.

int i=1;
int d=5;
d			
		





Output Writing – For loop break #7226 (15-Apr-2019)
In Topic(s) : Basic Loop Types    Jumping within loops   

Give the output of the following program segment and also mention the number of times the loop is executed:

int a,b;
for (a = 6, b = 4; a <= 24; a = a + 6)
{
  if (a%b ==0)
    break;
}
System.out.println(a);

Give the output of the following program segment and also mention the number





Array Filling – Name and Marks – Average and Deviation display #7198 (12-Apr-2019)
In Topic(s) : Array Basics   

Write a program to accept name and total marks of N number of students in two single subscript array name[ ] and totalmarks[ ].
Calculate and print:
(i) The average of the total marks obtained by N number of students.
[average = (sum of total marks of all the students)/N]
(ii) Deviation of each student’s total marks with the average.
[deviation = total marks of a student – average]

Write a program to accept name and total marks of N number of students in two


Patterns: ABCDE-ABCD-ABC-AB-A & B-LL-UUU-EEE #7196 (12-Apr-2019)
In Topic(s) : Pattern Printing   

Write a menu driven program to display the pattern as per user’s choice.
Pattern 1 Pattern 2
ABCDE       B
ABCD         LL
ABC            UUU
AB              EEEE
A
For an incorrect option, an appropriate error message should be displayed.

Write a menu driven program to display the pattern as per user’s choice.


Function Overloading – Volume #7194 (12-Apr-2019)
In Topic(s) : Function overloading   

Design a class to overload a function volume() as follows:

(i) double volume (double R) ¡V with radius (R) as an argument, returns the volume of sphere using the formula.
V = 4/3 x 22/7 x R^3
(ii) double volume (double H, double R) ¡V with height(H) and radius(R) as the arguments, returns the volume of a cylinder using the formula.
V = 22/7 x R^2 x H
(iii) double volume (double L, double B, double H) ¡V with length(L), breadth(B) and Height(H) as the arguments, returns the volume of a cuboid using the formula.
V = L x B x H

Design a class to overload a function volume() as follows:

(i) double


Pronic Number Check #7190 (12-Apr-2019)
In Topic(s) : Specially Named Numbers   

Write a program to input a number and check and print whether it is a Pronic number or not. (Pronic number is the number which is the product of two consecutive integers)
Examples: 12 = 3 x 4
20 = 4 x 5
42 = 6 x 7

Write a program to input a number and check and print whether it is a Pronic


: Quiz
Back