05.2 - PB Java While Loop Lab
05.2 - PB Java While Loop Lab
Problems for exercise and homework for the "Programming Basics" course @ SoftUni Global.
Submit your solutions in the SoftUni Judge system a: https://judge.softuni.bg/Contests/2395
1. Read Text
Write a program that reads text from the console (string) and prints it until it receives the "Stop" command.
2. In a while loop, until you enter a "Stop" command, read a new word and print it to the console:
2. Password
Write a program that reads a username and password. Then type the password again and check if it is correct
If the password is invalid: the user must type again his password.
If the password is correct: print "Welcome {username}!".
© SoftUni – https://softuni.org. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.
3. In the while loop, until you enter a valid password, read it again:
3. Sum Numbers
Write a program that reads an integer from the console and integers on each line until their sum is greater than or
equal to the original number. At the end of the reading, print the sum of the entered numbers.
2. Initialize the variable sum in which we will add the read numbers:
In a while loop, until the value of the originally read number is reached, read a new number and add it to the sum::
© SoftUni – https://softuni.org. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.
4. Sequence 2k+1
Write a program that reads the number n entered by the user and prints all the numbers ≤ n from the sequence: 1,
3, 7, 15, 3… Each next number is calculated by multiplying the previous one by 2 and adding 1.
3 1 8 1 17 1 31 1
3 3 3 3
7 7 7
15 15
31
2. 2. In a while loop until n is reached, calculate a new number from the sequence and print it:
5. Account Balance
Write a program that calculates how much money is in the account after you make a certain number of deposits.
On each line you will receive the amount you need to deposit in the account until you receive the command
"NoMoreMoney". For each amount received, the console must display "Increase: " + the amount and add it to the
© SoftUni – https://softuni.org. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.
6. Max Number
Write a program that, before receiving the "Stop" command, reads integers entered by the user and finds the
largest of them. Enter one number per line.
7. Min Number
Write a program that, before receiving the "Stop" command, reads integers entered by the user and finds the
smallest one of them. Enter one number per line.
8. Graduation
Write a program that calculates a student's average grade throughout his or her 12 years of study. On the first line
you will receive the student's name, and on each line their annual grades (12 grades in total). The student goes to
the next grade if their annual grade is greater than or equal to 4.00. If the student has failed more than once, they is
expelled, and the program ends by printing the student's name and in which class he needs to repeat.
Upon successful completion of 12th grade to print:
"{name of student} graduated. Average grade: {average grade through the years}"
In case the student is expelled from school, print:
© SoftUni – https://softuni.org. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.
© SoftUni – https://softuni.org. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.