Programr Code Exercises

284
751 reads
assign value


Language:Java
Difficulty Level:Easy
Questions:1
Attempts allowed:Unlimited
Available:Always
Pass rate:75 %
Time limit:0:30:00
Start exercise

Assume that an ArrayList of integers named a has been declared and initialized.

307
968 reads
inheritance2


Language:Java
Difficulty Level:Easy
Questions:1
Attempts allowed:Unlimited
Available:Always
Pass rate:75 %
Time limit:0:30:00
Start exercise

The superclass, EducationalInstitution, contains:
an int instance variable, duration, indicating the standard number of years spent at the institution

301
862 reads
Jukebox


Language:Java
Difficulty Level:Easy
Questions:1
Attempts allowed:Unlimited
Available:Always
Pass rate:75 %
Time limit:0:30:00
Start exercise

Problem: As an artistic student, with entrepreneurial interests, you decide to make a musical product. Your product is a simple software powered Jukebox, which will play a tune.

325
556 reads
replacing and converting Strings


Language:Java
Difficulty Level:Easy
Questions:1
Attempts allowed:Unlimited
Available:Always
Pass rate:75 %
Time limit:0:30:00
Start exercise

Problem: Jack Stealer has been suppressing his income from the Feds to save taxes.

275
997 reads
countdown using for loop


Language:Java
Difficulty Level:Easy
Questions:1
Attempts allowed:Unlimited
Available:Always
Pass rate:75 %
Time limit:0:30:00
Start exercise

Below is a program that takes an integer as input.
Write a for loop which prints a countdown from that number till 1
eg: if the inputted number is 4, then output should be:
4
3
2
1

Notes:

307
1251 reads
Fizz Buzz


Language:Java
Difficulty Level:Easy
Questions:1
Attempts allowed:Unlimited
Available:Always
Pass rate:75 %
Time limit:0:30:00
Start exercise

Problem: You are stranded in the Amazon rain forests with a robot who calls himself FizzBuzz.

254
749 reads
Suds


Language:Java
Difficulty Level:Easy
Questions:1
Attempts allowed:Unlimited
Available:Always
Pass rate:75 %
Time limit:0:30:00
Start exercise

Problem: We recently came across a very interesting thread on Reddit IAmA , which describes how a 24 year old boy conquered social anxiety. He describes how his therapist used a system called SUDS.

177
6805 reads
Multiplication Table


Language:Java
Difficulty Level:Medium
Questions:1
Attempts allowed:Unlimited
Available:Always
Time limit:0:30:00
Start exercise

Write a program which takes integer number and prints the table of that number.

Example :
1.If user gives input 2 then output table should be in the below format :
2
4
6
8
10
12
14
16

203
6589 reads
Capitalization


Language:Java
Difficulty Level:Medium
Questions:1
Attempts allowed:Unlimited
Available:Always
Time limit:0:30:00
Start exercise

Write a program which takes an input string and capitalizes only the first character of each word in the string, and does not affect the others.

Examples:

199
5932 reads
Nested for loops


Language:Java
Questions:1
Attempts allowed:Unlimited
Available:Always
Time limit:0:30:00
Start exercise

Complete the following program such that it prints numbers in triangular format as shown:
Eg:
Enter the size:4
Triangle is:
1
22
333
4444

Enter the size:6
Triangle is:
1
22

200
5190 reads
print even numbers using forloop


Language:Java
Questions:1
Attempts allowed:Unlimited
Available:Always
Time limit:0:30:00
Start exercise

Complete the below program such that it prints all even numbers upto the given size.
Ex: if user inputs 7, output should be:
0
2
4
6

Ex: if user inputs 14, output should be:
0
2
4

12
6364 reads
10
4685 reads
201
5827 reads
38
4427 reads
38
4804 reads
251
800 reads
Odds and Evens


Language:Java
Difficulty Level:Easy
Questions:1
Attempts allowed:Unlimited
Available:Always
Pass rate:75 %
Time limit:0:30:00
Start exercise

Problem: When this exercise is run, the program will ask the user to enter a number.

188
5292 reads
Count Occurrence of Character in string


Language:Java
Difficulty Level:Easy
Questions:1
Attempts allowed:Unlimited
Available:Always
Time limit:0:15:00
Start exercise

Write a program which takes input as string and also takes one character input and finds out the number of occurrence of the given character in string.

Example:

177
4350 reads
Euclids GCD Algorithm


Language:Java
Difficulty Level:Easy
Questions:1
Attempts allowed:Unlimited
Available:Always
Time limit:0:30:00
Start exercise

GCD of two numbers is Greatest Common Divisor for that numbers.

consider GCD for 12 and 24.
factors for 24 are 2,2,2,3
factors for 12 are 2,2,3

205
5964 reads
Armstrong Number


Language:Java
Questions:1
Attempts allowed:Unlimited
Available:Always
Time limit:0:30:00
Start exercise

Write a program to take input integer from the user and check out the entered number is Armstrong or not.
For e.g. :
1.If user gives input 153 then the output will be :

11
5239 reads
11
5402 reads
9
4654 reads
7
4335 reads
54
5319 reads
328
6349 reads
292
599 reads
Writer Echo


Language:Java
Difficulty Level:Easy
Questions:1
Attempts allowed:Unlimited
Available:Always
Pass rate:75 %
Time limit:0:30:00
Start exercise

Problem: When the exercise below is run, it will ask you to enter a String. The String that was entered, will be given to you in a variable called 'word'.

250
989 reads
writing a class


Language:Java
Difficulty Level:Easy
Questions:1
Attempts allowed:Unlimited
Available:Always
Pass rate:75 %
Time limit:0:30:00
Start exercise

Write a class named Averager containing:

An instance variable named sum of type integer, initialized to 0.

An instance variable named count of type integer, initialized to 0.

245
559 reads
Trickster


Language:Java
Difficulty Level:Easy
Questions:1
Attempts allowed:Unlimited
Available:Always
Pass rate:75 %
Time limit:0:30:00
Start exercise

Problem: Along with being a magician, you have also taught yourself the art of trickery by watching open courseware videos on Trickery 101.

222
829 reads
Beer


Language:Java
Difficulty Level:Easy
Questions:1
Attempts allowed:Unlimited
Available:Always
Pass rate:75 %
Time limit:0:30:00
Start exercise

Problem: You are at a party where Jake and Mike got a box full of beer cans for everyone.

163
4968 reads
Remove Character


Language:Java
Difficulty Level:Easy
Questions:1
Attempts allowed:Unlimited
Available:Always
Time limit:0:15:00
Start exercise

Write a program which takes a string and a character as inputs and remove the character from the string.

For Example :

199
7108 reads
ISBN Validation


Language:Java
Difficulty Level:Medium
Questions:1
Attempts allowed:Unlimited
Available:Always
Time limit:0:30:00
Start exercise

An ISBN number is legal if it consists of 10 digits and

d_1 + 2*d_2 + 3*d_3 + ... + 10*d_10 is a multiple of 11.

The ISBN number 0-201-31452-5 is valid.

199
4493 reads
Reciprocals Sum average and Product


Language:Java
Difficulty Level:Medium
Questions:1
Attempts allowed:Unlimited
Available:Always
Time limit:0:30:00
Start exercise

Write a program which accepts an integer n and calculates sum, product and average from 1 to 1/n i.e. n's reciprocals

for ex.
1) If user input 3.
then its sum from 1 to 1/3 = 1.803

172
5400 reads
Permutation of Strings


Language:Java
Difficulty Level:Medium
Questions:1
Attempts allowed:Unlimited
Available:Always
Time limit:0:30:00
Start exercise

Write a program to display all possible permutations of a given input string
if the string contains duplicate characters, you may have multiple repeated results.

For Ex :

6
4815 reads
12
5200 reads
10
4024 reads
130
5383 reads
57
4893 reads
6
4727 reads
239
425 reads
Tailless


Language:Java
Difficulty Level:Easy
Questions:1
Attempts allowed:Unlimited
Available:Always
Pass rate:75 %
Time limit:0:30:00
Start exercise

Problem:
One Friday evening after a tiring week of cranking out code, you decide to play tailless with your colleagues.

241
672 reads
Laziness thy name is ‘programmer’


Language:Java
Difficulty Level:Easy
Questions:1
Attempts allowed:Unlimited
Available:Always
Pass rate:75 %
Time limit:0:30:00
Start exercise

Problem: You have developed a pot belly with all the free beer your friends have been treating you, for the excellent Jukebox software.

268
497 reads
Sentiment analysis


Language:Java
Difficulty Level:Easy
Questions:1
Attempts allowed:Unlimited
Available:Always
Pass rate:75 %
Time limit:0:30:00
Start exercise

Problem: You recently decided to quit your 9:00 AM to 11:00 PM job, and become a freelance developer.

256
460 reads
Sesquipedalian


Language:Java
Difficulty Level:Easy
Questions:1
Attempts allowed:Unlimited
Available:Always
Pass rate:75 %
Time limit:0:30:00
Start exercise

Problem: A friend of yours is in the habit of using very big words. They constantly use words like gasconading, luminescent, and sesquipedalian, in their normal conversation.

176
8392 reads
Print Binary Triangle


Language:Java
Difficulty Level:Medium
Questions:1
Attempts allowed:Unlimited
Available:Always
Time limit:0:30:00
Start exercise

Write a program which takes input as integer and display the triangle of 0's and 1's on the basis of input integer.

Example:
1.If user gives input 5 then the triangle should be :
1
01
010

194
5798 reads
Triangular Numbers


Language:Java
Difficulty Level:Easy
Questions:1
Attempts allowed:Unlimited
Available:Always
Time limit:0:30:00
Start exercise

Complete the following program which takes the number as input and print the Sequences of numbers in triangular format up to that given height.
A program scenario is given below:
Example1:<

175
4121 reads
Convert binary to decimal


Language:Java
Difficulty Level:Medium
Questions:1
Attempts allowed:Unlimited
Available:Always
Time limit:0:30:00
Start exercise

Write a program which takes input binary number and convert this number in to decimal format.

For e.g:
1.If user gives input 101010 then the output should be 42.

199
4908 reads
Spring month check


Language:Java
Difficulty Level:Easy
Questions:1
Attempts allowed:Unlimited
Available:Always
Time limit:0:30:00
Start exercise

The duration between March 20 (inclusive) and June 20 (inclusive) is Spring time.

Write a program which takes month and day as positive integer input.
and shows whether its a spring time or not.

182
6320 reads
Sort Three numbers


Language:Java
Difficulty Level:Easy
Questions:1
Attempts allowed:Unlimited
Available:Always
Time limit:0:30:00
Start exercise

A very easy challenge.
Write a program which accepts 3 integers and sort them in ascending order.
For ex :
1) if user input 39 26 28 then output will be 26 28 39.

161
4292 reads
Prime Factors


Language:Java
Difficulty Level:Medium
Questions:1
Attempts allowed:Unlimited
Available:Always
Time limit:0:30:00
Start exercise

Write a program which accepts an integer and print its factors but the factors must be prime.

For ex :

1) if user inputs integer 369.
it should print 3 3 41 as prime factors.

189
5274 reads
Perfect number


Language:Java
Difficulty Level:Medium
Questions:1
Attempts allowed:Unlimited
Available:Always
Time limit:0:30:00
Start exercise

Complete the following program to find whether given number is perfect or not
Help(Perfect number is a positive number which sum of all positive divisors

199
4686 reads
Decimal to binary covertor


Language:Java
Difficulty Level:Medium
Questions:1
Attempts allowed:Unlimited
Available:Always
Time limit:0:30:00
Start exercise

Complete the following program to convert decimal number into binary form. Program will take input number from user and will display its binary equivalent.
Scenario should be same like given below

-3
4753 reads
9
4829 reads
9
4239 reads
13
4487 reads
13
5315 reads
183
731 reads
try catch


Language:Java
Difficulty Level:Easy
Questions:1
Attempts allowed:Unlimited
Available:Always
Pass rate:75 %
Time limit:0:30:00
Start exercise

Given you have a class AutoFactory with two static methods called shutdown and reset.
Neither method has any parameters. The shutdown method may throw a ProductionInProgressException.

240
602 reads
Arraylist Initialization


Language:Java
Difficulty Level:Easy
Questions:1
Attempts allowed:Unlimited
Available:Always
Pass rate:75 %
Time limit:0:30:00
Start exercise

Declare and initialize an ArrayList named denominations that contains 3 elements of type of Integer .

240
538 reads
List World Capitals


Language:Java
Difficulty Level:Easy
Questions:1
Attempts allowed:Unlimited
Available:Always
Pass rate:75 %
Time limit:0:30:00
Start exercise

Problem:
In this exercise, we have created a variable of type Map, called 'worldCapitals'. It contains the names of countries as keys and their corresponding capital as the value.

219
554 reads
inheritance


Language:Java
Difficulty Level:Easy
Questions:1
Attempts allowed:Unlimited
Available:Always
Pass rate:75 %
Time limit:0:30:00
Start exercise

Given the existence of a Phone class.

216
622 reads
Friendship


Language:Java
Difficulty Level:Easy
Questions:1
Attempts allowed:Unlimited
Available:Always
Pass rate:75 %
Time limit:0:30:00
Start exercise

Problem: A good conversationalist is not someone who talks a lot, rather it’s someone who gets the other person to talk.

178
532 reads
Protecting your turf


Language:Java
Difficulty Level:Easy
Questions:1
Attempts allowed:Unlimited
Available:Always
Pass rate:75 %
Time limit:0:30:00
Start exercise

Problem: Your Jukebox software has started becoming really popular. Being a firm believer in free and open source software, you share your code with all your friends.

219
623 reads
Grades


Language:Java
Difficulty Level:Easy
Questions:1
Attempts allowed:Unlimited
Available:Always
Pass rate:75 %
Time limit:0:30:00
Start exercise

Problem: After taking a few programming courses at the university, you apply for a summer internship at a local software company.

228
704 reads
Multiway If else


Language:Java
Difficulty Level:Easy
Questions:1
Attempts allowed:Unlimited
Available:Always
Pass rate:75 %
Time limit:0:30:00
Start exercise

Online Book Depot offers premium customers 1 free book with every purchase of 5 or more books and offers 2 free books with every purchase of 8 or more books.

171
6475 reads
Ulam Sequence


Language:Java
Difficulty Level:Medium
Questions:1
Attempts allowed:Unlimited
Available:Always
Time limit:0:30:00
Start exercise

A mathematician named Ulam proposed generating a sequence of numbers from any positive integer n (n > 0) is as follows:

If n is 1, stop.
If n is even, the next number is n/2.

156
4987 reads
Gray Code


Language:Java
Difficulty Level:Medium
Questions:1
Attempts allowed:Unlimited
Available:Always
Time limit:0:30:00
Start exercise

Gray Code is a modified binary code in which sequential numbers are represented by expressions that differ only in one bit, to minimize errors.

202
4756 reads
Cartesian to Polar co-ordinates


Language:Java
Difficulty Level:Medium
Questions:1
Attempts allowed:Unlimited
Available:Always
Time limit:0:30:00
Start exercise

Write a program which accepts cartesian coordinates x and y, and prints its polar coordinates form i.e. r and theta (degrees only).

For ex :

194
4881 reads
Find Vowels and Consonants


Language:Java
Questions:1
Attempts allowed:Unlimited
Available:Always
Time limit:0:30:00
Start exercise

Write a program which takes input as string and then implement the logic to findout Uppercase Consonants,Lowercase Consonants,Uppercase Vowels,Lowercase Vowels in string.

Example :

198
4562 reads
Reverse Floyds Triangle


Language:Java
Difficulty Level:Easy
Questions:1
Attempts allowed:Unlimited
Available:Always
Time limit:0:30:00
Start exercise

Write a program to implement a code for making reverse Flyod's triangle using loops. Floyd's Triangle: It is a pattern of numbers arranging in below format :
7_8_9_10_
4_5_6_
2_3_

177
4841 reads
Indian rupees formatter


Language:Java
Difficulty Level:Hard
Questions:1
Attempts allowed:Unlimited
Available:Always
Pass rate:75 %
Time limit:1:00:00
Start exercise

Complete the following program which takes input as a number and converts that number in to
Indian rupees format as given below in the examples.

134
5125 reads
While loop test


Language:Java
Questions:1
Attempts allowed:Unlimited
Available:Always
Time limit:0:30:00
Start exercise

While loop test:
Complete the program to display the numbers in reverse order from n till 1.
Ex:
if user input is 5
then output should be:
5
4
3
2
1

if user input is 7

12
4179 reads
10
4089 reads
58
5198 reads
200
5070 reads
219
1147 reads
Rhyme


Language:Java
Difficulty Level:Easy
Questions:1
Attempts allowed:Unlimited
Available:Always
Pass rate:75 %
Time limit:0:30:00
Start exercise

Problem: You enjoy reading out stories and rhymes to your daughter every night. However, this weekend you have to travel for a meeting, and you will be unable to read her a story.

210
429 reads
Generic Slapstick


Language:Java
Difficulty Level:Easy
Questions:1
Attempts allowed:Unlimited
Available:Always
Pass rate:75 %
Time limit:0:30:00
Start exercise

In this exercise, you have to add type information to List and ArrayList, so they are constrained to only hold String objects. The logic of the exercise has already been implemented.

224
2415 reads
Slapstick


Language:Java
Difficulty Level:Easy
Questions:1
Attempts allowed:Unlimited
Available:Always
Pass rate:75 %
Time limit:0:30:00
Start exercise

Problem: You watch a movie, which turns out to be a slapstick comedy, where the the lead character would repeat the line "and so be it", after everything he spoke.

203
1071 reads
Generic Retrieve World Capitals


Language:Java
Difficulty Level:Easy
Questions:1
Attempts allowed:Unlimited
Available:Always
Pass rate:75 %
Time limit:0:30:00
Start exercise

In this exercise, you have to add type (generic) information to the Map while creating it.

213
413 reads
Retrieve World Capitals


Language:Java
Difficulty Level:Easy
Questions:1
Attempts allowed:Unlimited
Available:Always
Pass rate:75 %
Time limit:0:30:00
Start exercise

Problem:
In this exercise, we have created a variable of type Map, called 'worldCapitals'. It contains the names of countries as keys and their corresponding capital as the value.

206
421 reads
Sorted


Language:Java
Difficulty Level:Easy
Questions:1
Attempts allowed:Unlimited
Available:Always
Pass rate:75 %
Time limit:0:30:00
Start exercise

Problem:
In this exercise, we will not spin any yarns. We will give you a list of String items, and you have to sort the List.

212
446 reads
Different Comparison


Language:Java
Difficulty Level:Easy
Questions:1
Attempts allowed:Unlimited
Available:Always
Pass rate:75 %
Time limit:0:30:00
Start exercise

In this exercise, we have created a class PersonComparator, which is an inner class of DifferentComparison.

228
438 reads
Comparison Is Not Evil


Language:Java
Difficulty Level:Easy
Questions:1
Attempts allowed:Unlimited
Available:Always
Pass rate:75 %
Time limit:0:30:00
Start exercise

In this exercise, you have to implement the compareTo method of the Person class, such that Person objects get compared based on their 'name' attribute.

208
397 reads
Brevity


Language:Java
Difficulty Level:Easy
Questions:1
Attempts allowed:Unlimited
Available:Always
Pass rate:75 %
Time limit:0:30:00
Start exercise

Problem: You recently read a blog post about the merits of using short sentences while writing. The article inspires you to write a program which will print the number of words in a sentence.

205
583 reads
abstract class


Language:Java
Difficulty Level:Easy
Questions:1
Attempts allowed:Unlimited
Available:Always
Pass rate:75 %
Time limit:0:30:00
Start exercise

Write a class definition for an abstract class, Vehicle, that contains:

a double instance variable, maxSpeed
a protected double instance variable, currentSpeed

179
521 reads
Concatenating Strings


Language:Java
Difficulty Level:Easy
Questions:1
Attempts allowed:Unlimited
Available:Always
Pass rate:75 %
Time limit:0:30:00
Start exercise

Problem: It is said that the ability of bringing people together for a good cause is almost divine.

236
587 reads
String Split


Language:Java
Difficulty Level:Easy
Questions:1
Attempts allowed:Unlimited
Available:Always
Pass rate:75 %
Time limit:0:30:00
Start exercise

A String variable, fullName, contains a name in one of two formats:
last name, first name (comma followed by a blank), or
first name last name (single blank)

225
507 reads
Dumbster


Language:Java
Difficulty Level:Easy
Questions:1
Attempts allowed:Unlimited
Available:Always
Pass rate:75 %
Time limit:0:30:00
Start exercise

Problem: You get drunk on a weekend, and forget your girlfriend’s birthday. She is so angry, that she makes you attend a party frequented by investment bankers.

206
518 reads
Menu


Language:Java
Difficulty Level:Easy
Questions:1
Attempts allowed:Unlimited
Available:Always
Pass rate:75 %
Time limit:0:30:00
Start exercise

Problem: You often enjoy dining at a Chinese restaurant near your house. Along with good food you also enjoy chatting with the manager, who always has interesting stories to tell.

228
534 reads
Magician


Language:Java
Difficulty Level:Easy
Questions:1
Attempts allowed:Unlimited
Available:Always
Pass rate:75 %
Time limit:0:30:00
Start exercise

Problem: Your peers think you are a magician. They think you can conjure arrays out of thin air. In the program below, you are given a variable called 'nums' which is of type array of integers.

216
612 reads
Spendthrift


Language:Java
Difficulty Level:Easy
Questions:1
Attempts allowed:Unlimited
Available:Always
Pass rate:75 %
Time limit:0:30:00
Start exercise

Problem: Mary usually stuffs her purse with plenty of $10 bills when she leaves her house. Once she reaches the market, she continues buying $10 items, until she runs out of money.

163
572 reads
Masked Odds and Evens


Language:Java
Difficulty Level:Easy
Questions:1
Attempts allowed:Unlimited
Available:Always
Pass rate:75 %
Time limit:0:30:00
Start exercise

Problem: When this exercise is run, the program will ask the user to enter a number.

162
762 reads
Rabbits


Language:Java
Difficulty Level:Easy
Questions:1
Attempts allowed:Unlimited
Available:Always
Pass rate:75 %
Time limit:0:30:00
Start exercise

Problem: You are walking with your girlfriend in the woods on a nice balmy April evening, and suddenly you see a bunch of rabbits. Look! you exclaim, so many rabbits.