0% found this document useful (0 votes)
13 views38 pages

Welcome To Java

This document serves as a beginner's guide to Java programming, focusing on conditional statements like 'if' and 'else'. It includes various exercises that cover basic input/output operations, arithmetic calculations, and logical comparisons. Each section provides sample inputs and expected outputs to help beginners practice and understand Java syntax and concepts.

Uploaded by

lawojim575
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views38 pages

Welcome To Java

This document serves as a beginner's guide to Java programming, focusing on conditional statements like 'if' and 'else'. It includes various exercises that cover basic input/output operations, arithmetic calculations, and logical comparisons. Each section provides sample inputs and expected outputs to help beginners practice and understand Java syntax and concepts.

Uploaded by

lawojim575
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 38

Java Question for absolute beginner

(Part 1 - if else)

INDEX
INDEX 1

1. Welcome to Java 3
2. Java Stdin and Stdout 4
3. Sum and Difference of x and y 5
4. Area and Perimeter 6
5. Fahrenheit and Celsius 7
6. Add Last Digits 8
7. Greater than 100 9
8. Sum is less than 150 or not. 10
9. XYZW 11
10. Even_Or_Odd 12
11. Grace Marks 13
12. Basic Calculator 14
13. Print two-digit number 15
14. Toggle and 2 jumps left 16
15. Marks and Rank 17
16. Adult or not 18
17. High Sum or Low Sum 19
18. Grade the student 20
19. Shop Discount 21
20. Print Bonus 22
21. Print final salary 23
22. Print z and x divisible by 3 24
23. Print the oldest among three 25
24. Rich Adult Young 26
25. Print final z 27
26. Tell about x y 28
27. Print the final incremented salary 30
2
28. Top Management or not 31
29. Print final z given xyz 32
30. Small Capital or Digit 33
31. Add if a digit 34
32. Toggle the character 35
33. Print character at 3rd index 36
34. Concatenate_Two_Strings 37
35. string concatenate 2 38

Return to index
3
Welcome to Java
In this challenge, we practise printing to stdout. Welcome to the world of Java!

System.out.println ("Hello World.");


System.out.println ("Hello Java.");

Input Format

There is no input for this challenge.

Output Format

You must print two lines of output:

1. Print Hello, World. on the first line.


2. Print Hello, Java. on the second line.

Sample Output

Hello World.
Hello Java.

Return to index
4
Java Stdin and Stdout
Most challenges require that you read input from stdin (standard input) and write output to stdout
(standard output). A popular method for reading input from stdin is by utilizing the Scanner class,
while specifying the Input Stream as System.in. For example:

Scanner scanner = new Scanner(System.in);


String myString = scanner.next();
int myInt = scanner.nextInt();
scanner.close();
System.out.println ("myString is: " + myString);
System.out.println ("myInt is: " + myInt);

The code above creates a Scanner object named and uses it to read a String and an int. It then
closes the Scanner object because there is no more input to read, and prints to stdout using
System.out.println(String). So, if our input is:

Hi 5

Our code will print:

myString is: Hi
myInt is: 5

Task

In this challenge, you must read byte, short, int, long, float, double boolean char, string from stdin
and then print them to stdout as shown. Each must be printed on a new line.

Input Format

There are lines of input, and each line contains a single integer.
Sample Input Sample output
1 Byte: 1
2 Short: 2
12 Int: 12
12000000000 Long: 12000000000
1.2 Float: 1.2
1.324 Double: 1.324
J Char: J
Java String: Java

Return to index
5
Sum and Difference of x and y
First integer input should be stored in x, Second integer input should be stored in y. You will be
given two integers x and y. You have to print the sum of x and y in the first line, and the difference
of x and y in the second line.

Input Format

In the first line the value of x will be given and in the second line the value of y will be given.

Constraints

Only integers will be given as input.

Output Format

Sum of x and y will be printed in the first line i.e x + y Difference of x and y will be printed in the
second line i.e x - y

Sample Input

40
10

Sample Output

50
30

Return to index
6
Area and Perimeter
Take the length and breadth of the rectangle as input.

Print the area of the rectangle in the first line and perimeter of the rectangle in the second line.

Input Format

In the first line, the length of the rectangle is given as input.

In the second line, the width of the rectangle is given as input.

Output Format

In the first line Area of the rectangle should be printed. In the second line the perimeter of the
rectangle should be printed.

Sample Input 0

10
20

Sample Output 0

200
60

Sample Input 1

20
30

Sample Output 1

600
100

Return to index
7
Fahrenheit and Celsius
You will be given Fahrenheit as input that should be stored in a double variable and print your
answer in Celsius of data-type double.

Input Format

In each input, you will get Fahrenheit as input.

Constraints

Fahrenheit will be given as a double data-type.

Output Format

For each test-case, you have to print Celsius in the double format.

Sample Input

32.0

Sample Output

0.0

Return to index
8
Add Last Digits
You will be given two numbers of int data-type as input, and you have to print the sum of their last
digits as output.

Given Inputs: 2357


48986

Expected Output: 13

Explanation: The last digit of 2357 is 7 and the last digit of 48986 is 6, and the sum of these last
digits is 13. Hence the output is 13.

Input Format

In the first line, the first number will be given as input. In the second line, the second number will
be given as input.

Constraints

Both the numbers will be positive and will be in integer format.

Output Format

Print the sum in the line.

Sample Input

23456
9873

Sample Output

Explanation

Since the last digit of 23456 is 6, and the last digit of 9873 is 3. Therefore the sum is 6+3 or 9.

Return to index
9
Greater than 100
You will be given an integer as input, you have to print true if the number is greater than 100, and
false otherwise.

Input: 110

Output: true

Explanation: Since the given input is greater than 100, we printed true.

Input Format

You will get an integer as input.

Constraints

-2^31<= Integer Input <= 2^31

Output Format

You have to print true or false.

Sample Input 0

120

Sample Output 0

true

Explanation 0

Since 120 is greater than 100, we have printed true.

Sample Input 1

90

Sample Output 1

false

Explanation 1

Since the input 90 is less than 100, we print false.

Return to index
10
Sum is less than 150 or not.
You will be given three integer inputs x, y, z.

You have to find the sum of these inputs.

Print true if the sum is less than 150 and false otherwise.

Input Format

First line, you will be given the value of x.

Second line, you will be given the value of y

Third line, you will be given the value of z.

Output Format

true or false accordingly

Sample Input

20
30
50

Sample Output

true

Explanation

Sum of 20, 30, 50 is 100, since the sum is less than 150 so we print true.

Return to index
11
XYZW
You will be given four integer inputs x, y, z, w. Print true if x * y is equal to z * w and false
otherwise.

Input Format

For each test-case In the first you will get x as integer input. In the second you will get y as integer
input. In the third you will get z as integer input. In the fourth you will get w as integer input.

Output Format

Print true or false accordingly.

Sample Input

5
8
10
4

Sample Output

true

Explanation

Since x=5, y=8, z=10, w=4.

xy is 40 and yz is 40, since xy is equal to yz so we print true.

Return to index
12
Even_Or_Odd
Take an integer value as input.

Print "Even" if the number is even, print "Odd" if the number is odd.

Note:- 0 will be considered as an even number.

Input Format

Input single line.

1. An integer value.

Output Format

Output single line.

1. A String "Even" Or "Odd".

Sample Input 0

98

Sample Output 0

Even

Sample Input 1

57

Sample Output 1

Odd

Return to index
13
Grace Marks
You are given the marks of a student as an integer input, the teacher gives 4 marks as grace marks
if the marks of the student is less than 33, otherwise no grace marks are given. Print the final
marks of the student.

Input Format

For each input, marks of a student will be given as an integer input.

Output Format

Print the final marks of a student in the integer output.

Sample Input

20

Sample Output

24

Explanation

Since the marks of the student is below 33, we add 4 marks as the grace marks, so the final marks
is 24.

Return to index
14
Basic Calculator
You will be given two integers x,y in the integer data-type format and a character as an input in the
character data-type format,

1. If the entered character is ‘A’, then print the value of x + y in the integer format.
2. If the entered character is ‘S’, then print the value of x - y in the integer format.
3. If the entered character is ‘M’, then print the value of x * y in the integer format.
4. If the entered character is ‘D’, then print the value of x / y in the integer format.
5. If the entered character is ‘R’, then print the value of remainder when x is divided by y.
6. Else print the string “Enter again”.

Input Format

For each input, You will get the value of x as an integer data-type in the first line, You will get the
value of y as an integer data-type in the second line, You will get a character as a character
data-type in the third line.

Output Format

Print according to the conditions given above.

Sample Input Sample Output

10 30
20
A

Explanation Entered character is 'A', we add the two integers and print the final sum as 30

50 -10
60
S

Explanation: Since the entered character is 'S', we print -10.

40 Enter again
30
k

Return to index
15
Print two-digit number
You will be given two digits x, y as character inputs, you need to form the two-digit number from it.
Print the final output based on the conditions given below,

1. If character x is zero, then print only the digit y in the integer data-type format.
2. Otherwise, print the number xy.

For example if x is ‘3’ and y is ‘8’, then print the number 38 in the integer data-type format.

Input Format

For each input,

You will get the digit character x as a character data-type in the first line,

You will get the digit character y as a character data-type in the second line.

Constraints

x and y can be any character.

Output Format

You have to print the final number.

Sample Input 0
5
6

Sample Output 0
56

Sample Input 1
0
8

Sample Output 1
8

Sample Input 2
6
0

Sample Output 1
60

Return to index
16
Toggle and 2 jumps left
Take in a character as an input from the user,

A. Condition 1 : If the character is an alphabet then you need to toggle the character first,

For example,

● if the entered character is ‘a’, then convert it into ‘A’, and if the entered character is ‘A’ then
convert it into ‘a’, this simply means that if the entered character is a capital case then
convert it into a small case character and vice-versa.
● After toggling the character: a. if the resultant character is not ‘a’, ‘A’, ‘b’, ‘B’, then take two
jumps to the left and print the character, for eg. If the toggled character is ‘c’ then print ‘a’,
If the toggled character is ‘Z’, then print ‘X’. b. If the toggled character is ‘a’, ‘A’, ‘b’, ‘B’, then
print “Sorry”.

B. Condition 2: Otherwise print “No alphabet”

Input Format

For each input, you will get a character as an input

Output Format

Print according to the given conditions.

Sample Input Sample Output

d B

Explanation Since the given character is 'd', its toggled character is 'D', after taking two jumps to
left, we print 'B'

Z x

a sorry

\ No alphabet

Return to index
17
Marks and Rank
Take in marks and rank of a student as integer inputs. Follow these conditions in a stepwise
manner: if the condition given before fails only then move on to the next condition, otherwise
don’t.

1. If marks are below 20 or rank is above 100, print “Needs improvement”


2. Or If marks are below 40 or rank is above 80, print “Concentrate”
3. Or If marks are below 60 or rank is above 120, print “Needs to focus”
4. Or if marks are above 100 or rank is below 10, print “Very good”
5. If none of the above condition follows, print “Bright Student”

Input Format

For each test case, you will be given

1. Marks of a student as an integer input in the first line,


2. Rank of the student as an integer input in the second line.

Constraints
31
0 <= 𝑚𝑎𝑟𝑘𝑠, 𝑟𝑎𝑛𝑘 <= 2 −1

Output Format

You need to print the string according to the conditions given.

Sample Input Sample Output

15 Needs improvement
90

Explanation Since the marks of the student is below 20, so we print the string "Needs
improvement"

25 Concentrate
75

Explanation Here the second condition follows, so we print the string "Concentrate"

55 Needs to focus
50

65 Bright Student 120 Very good


15 10

Return to index
18
Adult or not
You will be given the age of a person as an integer input. You need to check if the age is greater
than or equal to 18. If it is, print "Adult", otherwise, print “Below age”.

Input Format

For each input, you will get the age of a person as an integer input.

Output Format

Print "Adult" or "Below age" accordingly

Sample Input 0

20

Sample Output 0

Adult

Explanation 0

Since the age is 18 which is greater than or equal to 18, and so we print "Adult"

Return to index
19
High Sum or Low Sum
You will get two integer inputs x and y. You need to check if the sum of x and y is greater than or
equal to 100. If it is, print “High Sum”, otherwise, print “Low Sum”.

Input Format

You will get the value of x in the first line, You will get the value of y in the second line.

Output Format

You need to print "High Sum" or "Low Sum" accordingly.

Sample Input

40
70

Sample Output

High Sum

Explanation

Value of x is 40, the value of y is 70. So the sum is 110, since sum is greater than or equal to 100 so
we print "High Sum"

Return to index
20
Grade the student
You are given marks of a student as an integer input. You need to print according to the following
rules:

1. for marks above 90, print excellent.


2. for marks above 80 and less than equal to 90, print good.
3. for marks above 70 and less than equal to 80, print fair.
4. for marks above 60 and less than equal to 70, print meets expectations.
5. for marks above 40 and less than equal to 60, print below par.
6. prints failed if none of the above conditions follow.

Input Format

For each input, you will get marks of the student as an integer input.

Output Format

You need to print according to the rules given above.

Sample Input

92

Sample Output

excellent

Explanation

Since the marks entered by the user is above 90, so we print "excellent"

Return to index
21
Shop Discount
A shop will give a discount of 10% on the total cost if the cost of the quantity purchased is more
than 1000. a. Ask the user for the number of units, b. Suppose, one unit will cost 100. c. Judge and
print total cost for the user in the integer format.

Input Format

For each input, You will be given the number of units in the integer format.

Output Format

You have to print the final cost of the quantities.

Sample Input 0

15

Sample Output 0

1350

Explanation 0

The output is 1350, because the entered quantity is 15, so the cost of the units before the discount
is 1500, now 10% discount on 1500 is 150, so the final cost becomes 1500-150, which is equal to
1350.

Sample Input Sample Output

10 1000

9 900

11 990

8 800

Return to index
22
Print Bonus
Ask users for their salary and year of service and print the net bonus amount. The bonus in a
company is given by Bonus = Salary * (5 / 100). A company decided to give a bonus of 5% to
employees if his/her years of service is more than 5 years. If the years of service is less than or
equal to 5, print 0, otherwise print Bonus calculated.

Input Format

For each input, you will be given Salary of the user in the first line as an integer input. Years of
service in the second line as an integer input.

Output Format

Print the bonus of the employee in the integer format.

Sample Input

20000
6

Sample Output

1000

Explanation

Since the years of service are 6, we give the bonus. Hence the bonus is 1000.

Return to index
23
Print final salary
Take the age and salary of the person as integer inputs. And print his final income as an integer
data-type output. The government adds money into the account of a person based on his age: a. If
age is above 60, Rs. 1000 is added into the account. b. If age is above 40 and less than or equal to
60, Rs. 500 is added. c. No money is added if the age is less than or equal to 40.

Input Format

For each input, Age of the person in the first line, Salary of the person in the second line.

Output Format

Print his final income in an integer-data-type format

Sample Input 0

65
2000

Sample Output 0

3000

Explanation 0

Since the age of the person is above 65, we add 1000 into his bank account. Since his salary is
2000, his final salary becomes 3000.

Return to index
24
Print z and x divisible by 3
Take integer inputs x, y, z from the user,
If the x is divisible by 3, then
1. If y is greater than or equal to 200, then add 10 to the value of z.
2. Else if y is greater than or equal to 100 but less than 200, then add 5 to the value of z
3. Else if y is greater than or equal to 50, but less than 100, then add 4 to the value of z
4. Else add 1 to z
Else if x is not divisible by 3, then
1. If y is greater than or equal to 200, then add 3 to the value of z.
2. Else if y is greater than or equal to 100 but less than 200, then add 2 to the value of z
3. Else add 1 to z
In the end add 10 to the value of z and print the final value of z.
Input Format
For each input, You get the value of x in the first line as an integer input
You get the value of y in the second line as an integer input
You get the value of z in the third line as an integer input

Output Format
Print the final value of z as an integer output

Sample Input Sample Output

30 25
300
5

Explanation : Since x is 30 which is divisible by 3, and y is 300 which is greater than or equal to
200, so we add 10 to the value of z, so the value of z becomes 15.
In the end we add 10 to the value of z again, so now the value of z becomes 25.

41 19
150
7

Explanation : Since the value of x is 41, which is not divisible by 3, and value of y is 150 which is
greater than or equal to 100, so we add 2 to the value of z, so z becomes 7+2=9,
In the end, we add 10 to the value of z, so the value of z becomes 9+10=19.

Return to index
25
Print the oldest among three
You will be given the ages of three friends A,B,C as an integer input. You have to print the name of
the oldest friend among them.

Input Format

For each input, you will be given Age of A in the first line as an integer input Age of B in the second
line as an integer input Age of C in the third line as an integer input

Output Format

You have print A or B or C accordingly.

Sample Input 0

10
20
30

Sample Output 0

Explanation 0

Since C is the oldest among the three friends, we print C.

Sample Input 1

20
30
5

Sample Output 1

Explanation 1

Since B is the oldest among the three, we print B.

Return to index
26
Rich Adult Young
Take the age and salary of a person as an integer input, If the age is above 40 then

1. If the salary is greater than or equal to 30,000 then print “You are rich and adult”
2. Else print “You are an adult”

Else if age is less than or equal to 40

1. If the salary is greater than or equal to 12,000, then print “You are rich and young”
2. Else print “You are young”

Input Format

For each input, You will get the age of the person in the first line as an integer input, You will get
the salary of the person in the second line as an integer input.

Output Format

You have to print the output as a string accordingly.

Sample Input Sample Output

45 You are rich and adult


35000

Explanation: Since the age is above 40 and the salary is greater than or equal to 30000, so we
print "You are rich and adult"

35 You are young


10000

Explanation: Since the age is 30 which is less than or equal to 40 and salary is 10000 which is
less than 12000, so we print "You are young"

41 You are rich and adult


30000

Return to index
27
Print final z
Take input three numbers x, y, z as an integer input
Then if the value of x is greater than or equal to 20,
1. If the value of y is greater than or equal to 100 then add 100 to the value of z.
2. If the value of y is less than 100 and greater than or equal to 50, then add 50 to z.
3. Else add 10 to the value of z.
Else if the value of x is less than 20,
1. If the value of y is greater than or equal to 100 then add 3 to the value of z.
2. If the value of y is less than 100 and greater than or equal to 50, then add 2 to z.
3. Else add 1 to the value of z.
Print the final value of z as an integer output in the end.
Input Format

For each input, Value of x as an integer input will be given in the first line Value of y as an integer
input will be given in the second line Value of z as an integer input will be given in the third line

Output Format
Print the final value of z as an integer output

Sample Input Sample Output

30 130
120
30

Explanation : Since the value of x is 30 which is greater than or equal to 20, and the value of y is
120 which is greater than or equal to 100, so we add 100 to the value of z.

22 90
55
40

Explanation : Since the value of x is greater than or equal to 20, and the value of y is 55 which is
greater than or equal to 50 and less than 100, so we print 50 to the value of z. We print 90.

Return to index
28
Tell about x y
Take in two inputs x and y from the user, and then

1. If the value of x is greater than or equal to 59 and y is greater than or equal to 10, then
print “X is greater than or equal to 59 and y is greater than or equal to 10”
2. If the value of x is greater than or equal to 50, and y is less than 10, then print “X is greater
than or equal to 50 and y is less than 10”
3. Else print “None of the condition matches”

Input Format

For each input, you will get Value of x as an integer input in the first line, Value of y as an integer
input in the second line.

Output Format

Print the string according to the condition followed.

Sample Input 0
60
12

Sample Output 0
X is greater than or equal to 59 and y is greater than or equal to 10

Explanation 0

Since the value of x is 60 which is greater than or equal to 59, and the value of y is 12 which is
greater than or equal to 10, so we print the string "X is greater than or equal to 59 and y is greater
than or equal to 10"

Sample Input 1
55
8

Sample Output 1
X is greater than or equal to 50 and y is less than 10

Explanation 1
Since the value of x is 55 which is greater than or equal to 50, and the value of y is 8 which is less
than 8,so we print the string
X is greater than or equal to 50 and y is less than 10

Return to index
29
Sample Input 2
25
12

Sample Output 2
None of the condition matches

Explanation 2
Since the value of x is 25 which doesn't follow the condition 1 where it is written that the value of x
should be greater than or equal to 59, also the condition 2 is not followed as it is written in it that
the value of x should be greater than or equal to 50, Since none of the above 2 conditions follow,
so we print the string "None of the condition matches"

Sample Input 3
55
10

Sample Output 3
None of the condition matches

Sample Input 5
59
10

Sample Output 5
X is greater than or equal to 59 and y is greater than or equal to 10

Return to index
30
Print the final incremented salary
Take in three inputs age, salary, experience, then

1. If age is greater than 60 and salary is greater than 20,000 and experience is greater than 20
years, then add 5000 to the salary.
2. If age is greater than 40 and salary is greater than 15,000 and experience is greater than 10
years, then add 2000 to the salary.
3. If age is greater than 30 and salary is greater than 10,000 and experience is greater than 5
years, then add 1000 to the salary.
4. Otherwise add 500 to the salary.
In the end Print the final salary.

Input Format
For each input, You will get age as an integer input in the first line, You will get salary as an integer
input in the second line, You will get experience as an integer input in the third line.

Output Format
Print the final salary as an integer output.

Sample Input Sample Output

65 30000
25000
25

Explanation : Since the age is greater than 60 and salary is greater than 20,000 and experience is
greater than 20 years, so we add 5000 to the salary, hence we print 30000

30 15500
15000
7

Explanation : Since the age is 30, none of the conditions follow, so we add 500 to the salary.
Hence the final salary is 15500

40 15500 65 10500
15000 10000
5 25

Return to index
31
Top Management or not
Take in experience, salary and rank as integer inputs, then

1. If experience is greater than or equal to 10 years or the salary is greater than or equal to
50,000 or rank is greater than or equal to 10, then print “You are in top management”
2. Else print “You are not in top management”

Input Format

For each input, you will get Experience in the first line as an integer input, Salary in the second line
as an integer input, Rank in the third line as an integer input.

Output Format

You have to print the string "You are in top management" or "You are not in top management"
according to the conditions given in the problem statement.

Sample Input Sample Output

11 You are in top management


40000
9

Explanation: Since the experience of the person is 11 which is greater than or equal to 10 so the
first condition follows, hence the string "You are in top management" gets printed.

8 You are in top management


55000
8

Explanation: Since the salary is 55000 which is greater than or equal to 50000 so the first
condition follows, hence we print the string "You are in top management".

8 You are in top management


48000
11

Explanation Since the rank is 11 which is greater than or equal to 10, so the first condition
follows, hence we print the string "You are in top management"

Return to index
32
Print final z given xyz
Take in x, y, z as integer inputs from the user,
1. If x is greater than or equal to 20 and z is less than 100 then add 200 to the value of z.
2. If x is greater than or equal to 10, or y is less than 50 Then add 100 to the value of z.
In the end print the final value of z as an integer output.
Input Format

For each input, you will get


Value of x as an integer input in the first line,
Value of y as an integer input in the second line,
Value of z as an integer input in the third line.

Output Format

You have to print the final value of z as an integer output.

Sample Input Sample Output

25 280
30
80

Explanation Since the value of x is 25 which is greater than or equal to 20, and the value of z is
80 which is less than 100, hence the first condition follows, so we 200 to the value of z and
hence we print 80 + 200 = 280

25 290
45
190

Explanation Here the second condition follows so we add 100 to the value of z, so z becomes
190 + 100 = 290.

15 220
60
120

Return to index
33
Small Capital or Digit
Take in a character as an input and then
1. Print “Small case” if it is a small case character.
2. Print “Capital case” if it is a capital case character.
3. Print “Digit” if it is a digit.
4. Print “None” if none of the above conditions follow.
Input Format

For each input you will get a character as an input from the user.

Output Format

You have to print the string accordingly.

Sample Input 0
a

Sample Output 0
Small case

Explanation 0
Since the entered character is a small case character, so we print the string "Small case"

Sample Input 1
Z

Sample Output 1
Capital case

Sample Input 2
0

Sample Output 2
Digit

Sample Input 2
?

Sample Output 2
none

Return to index
34
Add if a digit
Take in a character as an input from the user
1. If the entered character is a digit, then add 100 to the value of the digit entered and print
the final answer. Convert the digit which is added as a character data-type into the integer
data-type using two ways
First: By using [Use the in-built function Character.getNumericValue]
Second using: By manipulating the digit character data-type into the integer data-type.
2. Else print “This is not a digit”
Input Format

For each input, you will get a character as a character data-type.

Output Format

Print according to the given conditions.

Sample Input 0

Sample Output 0

107

Explanation 0

Since the entered character is a digit, we add 100 to it and print the final answer.

Sample Input 2

Sample Output 2

This is not a digit

Explanation 2

Since the entered character is not a digit so we print the string "This is not a digit"

Return to index
35
Toggle the character
Take in a character as an input from the user

a. If the entered character is a small-case character, then convert it into the corresponding
uppercase character and print it.

b. If the entered character is an upper-case character, then convert it into the corresponding
lowercase character and print it.

Input Format

For each input, you will get an alphabet as a character input.

Constraints

The alphabet that is taken as input is only small-case or capital-case.

Output Format

You have to print the output as a character data-type.

Sample Input 0
a

Sample Output 0
A

Sample Input 1
K

Sample Output 1
k

Return to index
36
Print character at 3rd index
You will be given a string as an input, and

1. If the length of the string is greater than or equal to 4, then print the character at 3rd index.
2. Otherwise, print “Small string”

Eg. If the input string is "abcdef", then print d.

Input Format

For each input, you will get a string as input.

Output Format

You have to print according to the conditions mentioned above.

Sample Input 0
wxyza

Sample Output 0
z

Explanation 0
Since the length of the string is 5 which is greater than or equal to 4, we print the character at the
third index which is z.

Sample Input 1
abc

Sample Output 1
Small string

Sample Input 2
lmnopqr

Sample Output 2
o

Return to index
37
Concatenate_Two_Strings
Hello + Friends = HelloFriends

Take two strings as input by creating a Scanner object. Print the final string as output after
concatenation.

Input Format

Two Lines of input.

1. The first line of input will contain the 1st string.


2. The second line of input will contain the 2nd string.

Output Format

Single Line Output Output will be a single concatenated string.

Sample Input 0

Hello
Friends

Sample Output 0

HelloFriends

Return to index
38
string concatenate 2
Given 2 strings, a and b, return a string of the form short+long+short, with the shorter string on
the outside and the longer string on the inside. The strings will not be the same length, but they
may be empty (length 0). comboString("Hello", "hi") → "hiHellohi" comboString("hi", "Hello") →
"hiHellohi" comboString("aaa", "b") → "baaab"

Input Format

given two strings s1 and s2

Constraints

0 <= s1.length, s2.length <= 1000

s1.length != s2.length

Output Format

string representing short + long + short

Sample Input 0

hi
hello

Sample Output 0

hihellohi

Sample Input 1

hello
hi

Sample Output 1

hihellohi

Return to index

You might also like