logotransparent.png

Legion of Learners

www.lol-101.com

  • Home

  • Classrooms

  • Courses

  • About Us

    • Executive Team
    • Board Members
  • Resources

  • More

    Use tab to navigate through the menu items.
    To see this working, head to your live site.
    • Categories
    • All Posts
    • My Posts
    Warheadd Whiteoak
    Sep 28, 2020

    9/27 Homework: What does this program do?

    in CS Fundamentals for ACSL

    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


    7 comments
    0
    Henry Zheng
    Oct 02, 2020
    1. 1

    2. 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);

    }

    }


    0
    rayj.royw
    Oct 03, 2020

    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); } }

    0
    Shravya S
    Oct 04, 2020

    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

    0
    William Li
    Oct 04, 2020
    1. 25

    2. 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



    0
    Davey Yu
    Oct 04, 2020
    1. 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);

    }


    }


    }



    0
    dannyyu201
    Oct 04, 2020
    1. 25

    2. 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)

    }

    }

    0
    edward456jiang
    Oct 04, 2020

    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)




    0