1. What is the value of Z after this program is run?
2. Translate this pseudocode into real code:
Set z = 0 and n = 1000
While n is less than or equal to 2000 repeat this code:
a = n/1000 rounded down
b = (n- 1000*a)/100 rounded down
c = (n- 1000*a - 100*b)/10 rounded down
d = n - 1000*a - 100*b - 10*c
If a equals d and b equals c and a does not equal b then add 1 to z
Add 1 to n
Output z
Paste the entire program as your response along with what it outputs. As a bonus, you can describe the purpose of the program.
If you have forgotten some of the syntax, explanations and examples can be found here: http://www.categories.acsl.org/wiki/index.php?title=What_Does_This_Program_Do%3F
z = 0
n = 1000
while n <= 2000:
a = int(n / 1000)
b = int((n - 1000 * a) / 100)
c = int((n - 1000 * a) / 10)
d = n - 1000 * a - 100 * b - 10 * c
if (a == d) and (b == c) and (a != b):
z+=1
n+=1
print(z)
25
z=0
n=1000
While(n<_2000)
a=n/1000
b=(n-1000*a)/100
c=(n-1000*a-100*b)/10
d=n-1000*a-100*b-10c
If(a=d; b=c; a=b){
z+1
n+1
}
System.out.println(z)
}
}
25
import java.lang.*;
class Main {
public static void main(String[] args) {
int z = 0;
int n = 1000;
int a = 0;
int b = 0;
int c = 0;
int d = 0;
while(n<=2000) {
a = n/1000;
b = (n-1000*a);
c = (n-1000*a-100*b)/10;
d = n- 1000*a - 100*b - 10*c;
if(a == d && b == c && !a == b) {
z++;
}
n++;
System.out.println(z);
}
}
}
25
2. ↓ (import java.lang.Math first)
int z = 0;
int n = 1000;
int a = 0;
int b = 0;
int c = 0;
int d = 0;
while(n <=2000) {
a = Math.floor(n/1000);
b = Math.floor(n/100-10*a);
c = Math.floor(n/10-100*a-10*b);
d = n - 1000*a - 100*b - 10*c;
if(a=d && b=c && a !=b) {
z = z+1;
}
n = n+1;
}
System.out.println(z);
- William
1) 25
2) see below
z = 0 n = 1000 while n <= 2000: a = int(n/1000) b = int((n - 1000 * a) / 10) c = int((n - 1000 * a - 100 * b)/10) d = n - 1000 * a - 100 * b - 10 * c if (a == d) and (b == c) and (a != b): z += 1 n += 1 print(z)
Output: 1
1.1
2.class Main { public static void main(String[] args) { z = 0; n = 1000; a = 0; b = 0; c = 0; d =0; while(n <= 2000){ a = n/1000; b = (n - 1000*a)/100; c = (n-1000*a -100*b)/10; d = n - 1000*a - 100*b - 10*c; } if (a==d && b==c && a!=b){ z++; n++; } System.out.println(z); } }
1
see below
class Main {
public static void main(String[] args) {
int z = 0;
int n = 1000;
int a = 0;
int b = 0;
int c = 0;
int d = 0;
while(n <= 2000){
a = n/1000;
b = (n-1000*a)/100;
c = (n- 1000*a - 100*b)/10;
d = n - 1000*a - 100*b - 10*c;
}
if(a == d && b == c && a != b){
z++;
}
n++;
System.out.println(z);
}
}