0% found this document useful (0 votes)
14 views

Assignment 3 CSS 105

Uploaded by

madiar2007vvv
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)
14 views

Assignment 3 CSS 105

Uploaded by

madiar2007vvv
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/ 2

CSS 105 (Fundamentals of programming)

Assignment 3

1)Write a Java program to print all the LEADERS in the array.


Note: An element is leader if it is greater than all the elements to its right side.
Input: 10, 9, 14, 23, 15, 0, 9
Output: 23 15 9

2) Program Description for "Guess the Number" Game:


This Java program is a simple "Guess the Number" game where the user attempts to
guess a randomly generated number between 0 and 100. The program follows these
steps:
Generate a Random Number: The program generates a random integer between 0
and 100 (inclusive) using the Math.random() method, which is converted to an integer.
User Input: The program prompts the user to guess the randomly generated number.
The user enters their guess through the keyboard using the Scanner class.
Feedback Loop:
If the user's guess is higher than the actual number, the program informs them that their
guess is "too high."
If the user's guess is lower than the actual number, the program informs them that their
guess is "too low."
This process repeats in a loop until the user guesses the correct number.
Correct Guess: Once the user guesses the correct number, the program prints a
message congratulating them and reveals the number.
The game continues to prompt the user for guesses until the correct number is found,
providing immediate feedback on each guess.
3) Write a Java program to find the maximum difference between two elements in a
given array of integers such that the smaller element appears before the larger element.
Example:
Input : nums = { 2, 3, 1, 7, 9, 5, 11, 3, 5 }
Output: The maximum difference between two elements of the said array elements 10

4) There are two boxes. Size of the first box is A1 × B1 × C1, size of the second box is A2
× B2 × C2. Find out whether it is possible to put one of these boxes into the other if you
can rotate a box around any edge by 90 degrees.

The first line of input contains three integers A1, B1, C1 (1 ≤ A1, B1, C1 ≤ 1000). The
second line contains three integers A2, B2, C2 (1 ≤ A2, B2, C2 ≤ 1000).
If the boxes are equal, output "Boxes are equal". If the first box can be placed into
the second one, output "The first box is smaller than the second one". If the second box
can be placed into the first one, output "The first box is larger than the second one".
Otherwise, output "Boxes are incomparable".
Input : 1 2 3
321
Output: Boxes are equal

5) You are given a sequence consisting only of the characters '>', '<' and '-'. Find out the
number of arrows hidden in this sequence. Arrows are substrings of the form '>>-->' and
'<--<<'.
The first line of input contains no more than 250 characters '>', '<' and '-' without
spaces. The first line may or may not end with newline character(s).
Output one integer equal to the number of arrows.
Input : <<<<>>--><--<<--<<>>>--><<<<<
Output: 4

You might also like