0% found this document useful (0 votes)
70 views6 pages

Control Flow Statements - Branching

The document contains 9 questions on Java control flow statements and conditional logic. The questions cover topics like if-else statements, loops, methods, functions, arrays, strings and basic math/logical operations. Sample inputs and outputs are provided for each question to demonstrate expected behavior.
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)
70 views6 pages

Control Flow Statements - Branching

The document contains 9 questions on Java control flow statements and conditional logic. The questions cover topics like if-else statements, loops, methods, functions, arrays, strings and basic math/logical operations. Sample inputs and outputs are provided for each question to demonstrate expected behavior.
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/ 6

Assignment

Assignment #: 1

Topic : Control Flow Statement (Branching)

1. Write a Java program to read an integer variable Code. If the Code


value is 1,read double values for X and Y and calculate and print the sum

Sample Input1

Code :1

X : 24.50

Y : 67.00

Sample Output1

Sum : 91.50

Sample Input2

Code :4

Sample Output2

Sum : 0.00

2. Kumar is purchasing certain items in a store. While purchasing certain


items, a discount of 10% is offered to his if the quantity purchased is more
than 1000.Help, Kumar to calculate the total expenses.

Sample Input 1

Quantity Purchased : 1200

Rate per item : 15.50

Confidential v1.0
Sample Output 1

Total Expenses : 16740.000000

Sample Input 2

Quantity Purchased : 200

Rate per item : 15.50

Sample Output 2

Total Expenses : 3100.000000

3. Write a Java program, If integer variable currentNumber is odd,


change its value so that it is now 3 times currentNumber plus 1, otherwise
change its value so that it is now half of currentNumber.

Sample Input 1

currentNumber : 17

Sample Output

currentNumber : 52

Sample Input 2

currentNumber : 26

Sample Output

currentNumber : 13

4. Given 2 integer values, a and b , return their sum. However, "teen"


values in the range 13..19 inclusive, are extra lucky. So if either value is a
teen, just return 19.

Confidential v1.0
Sample Input1

a : 3

b : 4

Sample Output1

teenSum : 7

Sample Input2

a : 10

b : 13

Sample Output2

teenSum : 19

Sample Input3

a : 13

b : 12

Sample Output3

teenSum : 19

5. Write a java program to find the mobile chosen is within the budget or
not. To find the budget mobiles is based on the below-mentioned
criteria,
a) If the cost of the mobile chosen is less than or equal to 15000 then
display it as "Mobile chosen is within the budget"
b) If the cost of the mobile chosen is greater than 15000 then display it
as "Mobile chosen is beyond the budget“

Sample Input 1:
Enter the cost of the mobile
12000
Sample Output 1:
Mobile chosen is within the budget

Confidential v1.0
Sample Input 2:
Enter the cost of the mobile
22000
Sample Output 2:
Mobile chosen is beyond the budget

6. Ana planned to choose a four digit lucky number for his car. Her lucky
numbers are 3,5 and 7. Help her to find the number, whose sum is divisible
by 3 or 5 or 7. Provide a valid car number, Fails to provide a valid input
then display that number is not a valid car number.

Sample Input 1:
Enter the car no:1234
Sample Output 1:
Lucky Number
Sample Input 2:

Enter the car no: 1214

Sample Output 2:

Sorry its not my lucky number

Sample Input 3:

Enter the car no:14

Sample Output 3:

14 is not a valid car number

7. Write a java program to demonstrate the road signalling with default


as 'prepare to go' operation.

Assume red for 'stop', green for 'go', and yellow for 'proceed with caution'.

Sample Input 1:

Enter the color: green

Confidential v1.0
Sample Output 1:

Go

Sample Input 2:

Enter the color


red

Sample Output 2:

Stop

Sample Input 3:

Enter the color


yellow

Sample Output 3:

proceed with caution

Sample Input 4:

Enter the color


white

Sample Output 4:

prepare to go

8. Riya's teacher has asked her to prepare well for the lesson on seasons.
When her teacher tells a month, she needs to say the season corresponding
to that month. Write a program to solve the above task.

Spring - March to May,

Summer - June to August,

Autumn - September to November and,

Winter - December to February.

Confidential v1.0
Month should be in the range 1 to 12. If not the output should be
"Invalid month".

Sample Input 1:
Enter the month:11

Sample Output 1:
Season:Autumn

Sample Input 2:
Enter the month:13

Sample Output 2:
Invalid month

9. Create a JAVA program to display the "text" corresponding to a certain


"numerical value", using the following equivalence:

9,10 = Excellent
7,8 = Notable
6 = Good
5 = Approved
0-4 = Fail

>=10= Invalid

Sample Input1

Sample Output1

Excellent

Sample Input2

Sample Output2

Fail

Confidential v1.0

You might also like