Help. How? why? | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
+ 6

Help. How? why?

int x = 3,y=0; do {--x; y+=x; } while(x>0); System.out.println(y);

28th Mar 2019, 9:43 AM
Iftakher Hossain
Iftakher Hossain - avatar
3 ответов
+ 9
This is a simple program code for do while loop. Here is the simplest explanation in the form of a dry run of the above program code. Initially, x=3 & y=0 The subsequent values of x and y are shown in the table below: x | y | x>0 ----------------------------------- 3 | 0 | - 3-1= 2 | 0+2=2 | true 2-1=1 | 2+1=3 | true 1-1=0 | 3+0=3 | false Hence the final output is the final value of y which is 3. Happy Learning :)
28th Mar 2019, 10:20 AM
Sulagna Dutta
Sulagna Dutta - avatar
+ 3
Thanks all. very helpful to me. thanks again.
28th Mar 2019, 10:35 AM
Iftakher Hossain
Iftakher Hossain - avatar
- 2
Java programm All kenyan employee earning Gross salary(basic salary +allowance)of over 11000 are subject to an income tax of 30% of basic salary.In addition the following deduction must be made 1.pension contribution of 5% basic salary 2.NHIF of 1200 for gross salary of 100,000 and above while 320 deduction for gross salary below 100,000 3. NSSF of 200 Write a program with one class and several methods performing different computation . The main {} method should contain appropriate statements that prompt the user to enter name,basic salary and house allowance it should also display the payslip as follows Employee Name: Gross pay: Tax: Pension: NHIF: NSSF: Net pay : There should be 5 different value returning methods to compute and return tax,pension,NHIF, NSSF and net pay NB; NET PAY=GROSS PAY -(TAX +PENSION+NHIF+NSSF) Help with this question
28th Mar 2019, 3:52 PM
BRIAN ONSONGO ONDUKO
BRIAN ONSONGO ONDUKO - avatar