Problem Solving in Java - 20 problems clear your basic. | Java Programming



This Article for them who have basic knowledge of java but begainer in problem solving. it covered concepts of if-else statement , Array and String manipulation.


At first try your self. you can get help of video tutorial if you failed several time. Solution link given at the bottom of this article.

1. Print the following shapes using loop(s)



2. Write a program to generate the following output (in the given layout) using
loop(s).


3. Write a program that takes the height and width of a square and print the box of
that height and width with alphabet ‘B’. E.g. if user presses 5 for height and 8 for
width, your program should print the following. (Restrict the user such that
height or width should not be equal to zero).

4. Develop a program that inputs 10 different integers within a while loop and
displays the largest as well as smallest. (Repetition of numbers is not allowed).


5. Write a program that asks the base and exponent (power) from user and print
the result using do while loop. e.g. If base is 2 and exponent is 3, so 2*2*2 is 8.


6. Using for loop, print the result of multiplication of all odd numbers from 1 to 20
and the result of sum of all even numbers from 1 to 100.


7. Print the following shapes using loop(s)



8. Take an integer input from the user, print YES if it is prime number and NO if it
not a prime number. (Prime number is a number which is only divisible by 1 or
itself).


9. using do while print the number of digits this number contains.


10. Take two numbers from the user and print the result of multiplication and
sum of all the numbers between these two numbers. E.g. if user presses 3 and 8
then 4+5+6+7 is 22 and 4*5*6*7 is 840. (Restrict the user such that first
number must be less than the second number).


11. Take an integer input from the user and count all prime numbers from 1 up
to that number, print the total number of prime numbers as well as the largest
one. E.g. if user presses 20, your program should print “Total number of prime
numbers are: 8” (as prime numbers from 1 to 20 are 1, 3, 5, 7, 11, 13, 17, 19)
and “Largest prime number is: 19”.


12. Write a program which asks the user “How many prime numbers you want to
print: “, you have to print that much prime numbers as well as the sum of all
printed prime numbers. If user presses 11, your program should print first eleven
prime numbers, these are 1 3 5 7 11 13 17 19 23 29 31 and sum of these
printed numbers, that is 159. (Restrict the user such that input should not be
negative).


13. Take two integer arrays of 10 indices each and initialize them. Then copy
the contents of both of the arrays in a third array, one consecutive index from
one array at a time.
E.g. if the array1 has 1 2 3 4 5 6 7 8 9 10 stored and array2 has 11 12 13 14 15 16 17 18 19 20 stored then array three will have 1 11 2 12 3 13 4 14 5 15 6 16 7 17 8 18 9 19 10 20 stored.


14. Initialize integer array with 10 random values. Then print the second
smallest as well as second largest element from that array. (E.g. 23 7 2 56 3 8 9.
here second largest is 23 and second smallest is 3). you code might not work for 1 2 2 2 2 5 5 8 8 8 8 8, second largest is 5 and second smallest is 2. You have to
check ur program with many test cases.


15. Declare an array and take input from the user in that array, ask the user to
enter an integer and you have to print index number of that integer. if that
number exists 2 or more time at different indexes then u have to print all indexes
having that integer input.


16. Declare array and take input from the user to fill that array, take two
integer input from the user, you have to find indexes of those numbers and than
exchange those number. if 45 comes at index 3 and 67 comes at index 9. After
exchange, index 3 should contain 67 and index 9 should contain 45.


17. Declare and take input from the user in two arrays a and b, you have to print
all the numbers which exist in both the arrays.


18. Declare and take input from the user in character array, and you have to
print total number of vowels in that array (e.g. d t i o o a r w h s h w q n x b , total number of vowels are 4 (as i o o a ) ).


19. Take two arrays of character type and take input from the user, you have to
exchange the elements of both arrays. array A should contains elements of B, and
B should contain the elements of A.


Credit and Solution Link: https://youtu.be/Sny9Rta3k_Q

Basic Problem Solving using C Programming Language | Programming Basic


Problem Solving:
Note: At first try yourself by "Hide Solution" and if you failed then "Show Solutions". Happy Coding :)

Problem 1:  Write your first program which will print "Hello World"
Solution:

Problem 2:  Write a program which will take input two numbers from user and print.
Solution:

Problem 3:  Write a program which will take input a character from user and print.
Solution:

Problem 4:  Write your first program which will print "Hello World"
Solution:

Problem 5:  Write your first program which will print "Hello World"
Solution:

Problem 6:  Write your first program which will print "Hello World"
Solution:

Problem 7:  Write your first program which will print "Hello World"
Solution:

Problem 8:  Write your first program which will print "Hello World"
Solution:

Problem 9:  Write your first program which will print "Hello World"
Solution:

Problem 10:  Write your first program which will print "Hello World"
Solution:

Problem 11:  Write your first program which will print "Hello World"
Solution:

Problem 12:  Write your first program which will print "Hello World"
Solution:

Problem 13:  Write your first program which will print "Hello World"
Solution:

Problem 14:  Write your first program which will print "Hello World"
Solution:

Problem 15:  Write your first program which will print "Hello World"
Solution:

Problem 16:  Write your first program which will print "Hello World"
Solution:

Problem 17:  Write your first program which will print "Hello World"
Solution:

Problem 18:  Write your first program which will print "Hello World"
Solution:

C Programming (Problem & Solutions) by Md. Ashraf-ul Asad | PDF Book [Free Download]


C Programming 
 Md. Ashraf-ul Asad | Free PDF Book


Details: The best C programming Practice Book written By Md. Ashraf-ul Asad - Lacturer , University Of Rajshahi.


Book Screenshot 



Free Download


Computer Programming - Tamim Shahriar subeen | PDF Book [Free Download]


Computer Programming 
 Tamim Shahriar subeen | Free PDF Book


Details: The Best Bangla C Programming book ever. written by Tamim Shahriar Subeen and Published with Dimik Prokashoni. It has three sequence Part-1, Part-2 and Part-3. That is Part-1 and we are being ready to upload others part of this book very soon. Stay Connected.

Book Cover 




Free Download








Learn About Primary Data Types - C Programming | Programming Basic

Data Types - C Programming

Data types in c refer to an extensive system used for declaring variables or functions of different types. The type of a variable determines how much space it occupies in storage and how the bit pattern stored is interpreted.
Integer Types
The following table provides the details of standard integer types with their storage sizes and value ranges −
TypeStorage sizeValue range
char1 byte-128 to 127 or 0 to 255
unsigned char1 byte0 to 255
signed char1 byte-128 to 127
int2 or 4 bytes-32,768 to 32,767 or -2,147,483,648 to 2,147,483,647
unsigned int2 or 4 bytes0 to 65,535 or 0 to 4,294,967,295
short2 bytes-32,768 to 32,767
unsigned short2 bytes0 to 65,535
long8 bytes-9223372036854775808 to 9223372036854775807
unsigned long8 bytes0 to 18446744073709551615
Given below is an example to get the size of various type on a machine using different constant defined in limits.h header file −
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <float.h>

int main(int argc, char** argv) {

    printf("CHAR_BIT    :   %d\n", CHAR_BIT);
    printf("CHAR_MAX    :   %d\n", CHAR_MAX);
    printf("CHAR_MIN    :   %d\n", CHAR_MIN);
    printf("INT_MAX     :   %d\n", INT_MAX);
    printf("INT_MIN     :   %d\n", INT_MIN);
    printf("LONG_MAX    :   %ld\n", (long) LONG_MAX);
    printf("LONG_MIN    :   %ld\n", (long) LONG_MIN);
    printf("SCHAR_MAX   :   %d\n", SCHAR_MAX);
    printf("SCHAR_MIN   :   %d\n", SCHAR_MIN);
    printf("SHRT_MAX    :   %d\n", SHRT_MAX);
    printf("SHRT_MIN    :   %d\n", SHRT_MIN);
    printf("UCHAR_MAX   :   %d\n", UCHAR_MAX);
    printf("UINT_MAX    :   %u\n", (unsigned int) UINT_MAX);
    printf("ULONG_MAX   :   %lu\n", (unsigned long) ULONG_MAX);
    printf("USHRT_MAX   :   %d\n", (unsigned short) USHRT_MAX);

    return 0;
}

Floating-Point Types

The following table provide the details of standard floating-point types with storage sizes and value ranges and their precision −
TypeStorage sizeValue rangePrecision
float4 byte1.2E-38 to 3.4E+386 decimal places
double8 byte2.3E-308 to 1.7E+30815 decimal places
long double10 byte3.4E-4932 to 1.1E+493219 decimal places
The following example prints the storage space taken by a float type and its range values −
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <float.h>

int main(int argc, char** argv) {

    printf("Storage size for float : %d \n", sizeof(float));
    printf("FLT_MAX     :   %g\n", (float) FLT_MAX);
    printf("FLT_MIN     :   %g\n", (float) FLT_MIN);
    printf("-FLT_MAX    :   %g\n", (float) -FLT_MAX);
    printf("-FLT_MIN    :   %g\n", (float) -FLT_MIN);
    printf("DBL_MAX     :   %g\n", (double) DBL_MAX);
    printf("DBL_MIN     :   %g\n", (double) DBL_MIN);
    printf("-DBL_MAX     :  %g\n", (double) -DBL_MAX);
    printf("Precision value: %d\n", FLT_DIG );

    return 0;
}

ASCII Table Lookup - Important For Programmers & Developers


ASCII Table Lookup
ASCII stands for American Standard Code for Information Interchange. There are 128 standard ASCII codes, each of which can be represented by a 7-digit binary number: 0000000 through 1111111.
Extended ASCII adds an additional 128 characters that vary between computers, programs and fonts.

DECOCTHEXBINSymbolHTML CodeDescription
00000000000000NUL&#000;Null char
-
4806030001100000&#48;Zero
4906131001100011&#49;One
5006232001100102&#50;Two
5106333001100113&#51;Three
5206434001101004&#52;Four
5306535001101015&#53;Five
5406636001101106&#54;Six
5506737001101117&#55;Seven
5607038001110008&#56;Eight
5707139001110019&#57;Nine
580723A00111010:&#58;Colon
590733B00111011;&#59;Semicolon
600743C00111100<&#60;Less than
610753D00111101=&#61;Equals
620763E00111110>&#62;Greater than
630773F00111111?&#63;Question mark
641004001000000@&#64;At symbol
651014101000001A&#65;Uppercase A
661024201000010B&#66;Uppercase B
671034301000011C&#67;Uppercase C
681044401000100D&#68;Uppercase D
691054501000101E&#69;Uppercase E
701064601000110F&#70;Uppercase F
711074701000111G&#71;Uppercase G
721104801001000H&#72;Uppercase H
731114901001001I&#73;Uppercase I
741124A01001010J&#74;Uppercase J
751134B01001011K&#75;Uppercase K
761144C01001100L&#76;Uppercase L
771154D01001101M&#77;Uppercase M
781164E01001110N&#78;Uppercase N
791174F01001111O&#79;Uppercase O
801205001010000P&#80;Uppercase P
811215101010001Q&#81;Uppercase Q
821225201010010R&#82;Uppercase R
831235301010011S&#83;Uppercase S
841245401010100T&#84;Uppercase T
851255501010101U&#85;Uppercase U
861265601010110V&#86;Uppercase V
871275701010111W&#87;Uppercase W
881305801011000X&#88;Uppercase X
891315901011001Y&#89;Uppercase Y
901325A01011010Z&#90;Uppercase Z
911335B01011011[&#91;Opening bracket
921345C01011100\&#92;Backslash
931355D01011101]&#93;Closing bracket
941365E01011110^&#94;Caret - circumflex
951375F01011111_&#95;Underscore
961406001100000`&#96;Grave accent
971416101100001a&#97;Lowercase a
981426201100010b&#98;Lowercase b
991436301100011c&#99;Lowercase c
1001446401100100d&#100;Lowercase d
1011456501100101e&#101;Lowercase e
1021466601100110f&#102;Lowercase f
1031476701100111g&#103;Lowercase g
1041506801101000h&#104;Lowercase h
1051516901101001i&#105;Lowercase i
1061526A01101010j&#106;Lowercase j
1071536B01101011k&#107;Lowercase k
1081546C01101100l&#108;Lowercase l
1091556D01101101m&#109;Lowercase m
1101566E01101110n&#110;Lowercase n
1111576F01101111o&#111;Lowercase o
1121607001110000p&#112;Lowercase p
1131617101110001q&#113;Lowercase q
1141627201110010r&#114;Lowercase r
1151637301110011s&#115;Lowercase s
1161647401110100t&#116;Lowercase t
1171657501110101u&#117;Lowercase u
1181667601110110v&#118;Lowercase v
1191677701110111w&#119;Lowercase w
1201707801111000x&#120;Lowercase x
1211717901111001y&#121;Lowercase y
1221727A01111010z&#122;Lowercase z
-