Jump to content

Recommended Posts

  • 2 weeks later...
Posted

Hi,

I  need help with codes on pictures in attachments. I need it "now" cause I must pass the exam of programming who's I hate. Thanks for help!

 

http://i45.tinypic.com/35na1zm.jpg

http://i50.tinypic.com/14wgm13.jpg

 

we dont understand this language, translate exercises in english.

  • 2 weeks later...
Posted

They are wrote in polish language, i know its been a while but maybe u will learn something:

1. What variables will print on the screen below fragment of the program?

int e[][]={{45,5,6},{7,9,4},{8,8,9}};
for(int x[]:e) for(int y:[x]) System.out.print(y);

ok so in first line we have got 2 dimensional table, first[] before e, are all variables inside {}, so e[1] will give us {7,9,4}, but we always need to write something in 2nd [], which means number inside {}.

e[0][1] will give us 5, e[2][2] will give us 9.

for(int x[]:e) - thats something harder, we have got a loop which will create for us 3, 1 dimensioned tables, so first we will have int[] x = {45,5,6}; later x will be {7,9,4} and at the end {8,8,9}; so if we would have something like this:

for(int x[]:e) System.out.print(x[0]);

4578 - would appear.

now for(int y:[ x ]) - that doesnt exist in java 1.7, it should be for(int y:x) - loop will create y variable for each number in the table.

So first (y=45,x=0), (y=5,x=0), (y=6,x=0), (y=7,x=1) etc

what we have at the last is System.out.print(y).

So we will have 4556794889 :)

 

2.Create new object of class B, run method and set any value to variable i

class A {int i=10 ; int metoda(){int b=10; return b; }}
class B extends A {int i ; int metoda(int t){byte b=10; return b+t;}}

B ob = new B(); - creating new object of class B

ob.i = 123; - setting any value to variable i

 

3.What implements function?

 void function(){ int n=10; int[][] tab=new int[n][];
for(int i=0;i<n;i++) tab[i]=new int[i+1];
System.out.println(tab.length); System.out.println(tab[n-1].length); }

So, int[][] tab=new int[n][]; - we are creating new 2 dimensional table, tab length will be now n(10)

for(int i=0;i<n;i++) tab[i]=new int[i+1];

tab[0] length will be 1, tab[1] length will be 2 etc.

System.out.println(tab.length); - will give us tab length = 10

System.out.println(tab[n-1].length); - will give us length of tab[9], it will be 10

 

4.What will be printed on the screen?

 void function(){ int n=4; for(int i=n;i>1;i--){ for(int j=0;j<i;j++)
System.out.print(" "); System.out.println("*");} }

for(int i=n;i>1;i--)

- this loop will work 3 times, 4>1, 3>1 and 2>1, in each case, 2nd loop will start

for(int j=0;j<i;j++)

- when i=4, this will work 4 times(j=0, j=1, j=2 and j=3), each time j is increased, to the screen is added " ", and each time i is decreased, "*" and skipping to next line is printed so it will be like this:

    *
   *
  *

 

5. What will appear on the screen?

public class rozne {
enum wyliczenie {Syrenka(500), Fiat125p, OpelCorsa(25000), Yaris(26000), Laguna(45000);
private int cena;
wyliczenie(int cena){this.cena=cena;}
wyliczenie(){ this.cena=-1;}
int cena()Preturn cena;}
}
public static void main(String[] args) {
for(wyliczenie x: wyliczenie.values())
odpowiedz(x);
}
static void odpowiedz(wyliczenie ob)
{
switch(ob)
{
case Syrenka : System.out.print("\t Samochod ="+ob);
case Fiat125p : System.out.print("\t Samochod ="+ob);break;
case Laguna : System.out.print("\t Samochod ="+ob); break;
}}}

Ok so, this is runned first:

for(wyliczenie x: wyliczenie.values())

so each value of enum Wyliczenie will be in variable x, first x=Syrenka, 2nd x=Fiat125p etc

each time method odpowiedz is runned, we are going to switch - putting our x(now ob) inside and we are checking if ob=Syrenka later if ob=Fiat125p and at the end if ob=Laguna

so, at the beggining ob is Syranka, so we are printing \t - thats Tabulator, Samochod=Syrenka.

But hey, we dont have a break after that, so its not being closed, we are printing it 2nd time, now our text will be like this:

	 Samochod =Syrenka	 	 Samochod=Syrenka

later into odpowiedz, we are putting Fiat125p, it is printed only once since after System.out.print is break;

we are not printing OpelCorsa because we dont have anything like that in switch

at the end it will be like this:

 Samochod = Syrenka	 Samochod = Syrenka	 Samochod = Fiat125p	 Samochod = Laguna

 

6. What's wrong with the code?

class A{int a; public A(int i){a=4*i;}
void pokaz(){System.out.print(a);}}
class B extends A{int b; public B(int i, int j){super(i); b=2*j;}}
public class Main{ public static void main(String[] args){
B ob = new B(3,5); A oa; A o=new A(3); oa.pokaz();}}

Whats wrong with the code? hmm or isnt initialized, u cannot use oa.pokaz() on null or not yet initialized reference :)

 

7. What will appear in the screen?

class A{int a=1; int b=2; public A(int i,int j){}
public A(A o){a=2*o.a; b=3*o.b;} void pokaz(){System.out.println(a+"_"+b);} }
public class Main { public static void main(String[] args) {
A oa= new A(0,0);A ob= new A(oa);A oc= new A(ob);oc.pokaz(); }}

ok so first, this is runned: A oa= new A(0,0); - we are creating new object, i=0, j=0 but inside {} we have got nothing, so we are going to next line:

A ob= new A(oa); - now we have got a=2*o.a(1) so a=2, b=3*o.b(2), so b=6

A oc= new A(ob); - same thing, a=2*2=4, b*3*6=18

oc.pokaz(); - "4_18" will be printed on the screen :)

 

Hope that i helped somebody :)

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Posts

    • LIVE VERIFICATION? SUMSUB? “IMPOSSIBLE”? ▪ Spoiler: it is possible — if you know who to work with. A client came in with a task to pass **live verification** on **WantToPay**, a Telegram virtual card service. On the platform side — **Sumsub**: liveness check, SMS, manual review. “Fast” and “by eye” simply don’t work here. › What was done: → analyzed the verification scenario and Sumsub requirements → built the correct flow: phone number, email, timing → **completed live verification remotely, without account handover** → handled SMS and confirmation codes → brought the process to final approval ▪ Result: → verification passed → access granted → no flags or repeat requests ▪ Live verification is not luck. It’s scenario-based preparation — not hope. › TG: @mustang_service ( https:// t.me/ mustang_service ) › Channel: Mustang Service ( https:// t.me/ +6RAKokIn5ItmYjEx ) *All data is published with the client’s consent.* #verification #sumsub #livecheck #kyc #case
    • IMPORTANT INFO: In a few days, I will switch to completely new code, written from scratch with a new download system, patch building and management system. The Updater will become true 2026 code with "foolproof systems". I'm going to create a Discord server for customers to request new ideas and features. FIRST CUSTOMERS ARE ALREADY USING THE NEW UPDATER ON LIVE SERVERS! Watch this topic for upcoming info because the new updater is around the corner! Yes, you can still use self-update on the previous updater! No, the new updater won't be compatible with the old patch system! A new build is required, but players who already have game files won't have to download the entire patch again! New templates and updates to existing templates are coming soon! Sneak peek:  
    • i used guytis IL project and source. i found in his project there are 3 Client version source... 1,CliExt_H5   --->this one cant be compiled in VS2005,i did know why..is it for H5 client? 2,CliExtNew  --->this one is IL version ,but when i compiled it and use it.player cant login game,MD5Checksum wrong.i check the source code,but not found any hints. 3,L2Server    --->this one for HB client?im not sure...   so my question is what are the differences between these three versions of cliext.dll?how can i fix the issue of the MD5Checksum not matching problem?   01/29/2026 21:04:11.366, [CCliExt::HandleCheckSum] Invalid Checksum[1130415144] vs [-721420287] packet[dd] len[29] sum[2698] key[30] HWID[] Account[]! 01/29/2026 21:04:11.366, SocketLimiter::UserSocketBadunknownprotocol 11111111111 01/29/2026 21:04:11.366, [usersocket]unknown protocol from ip[113.137.149.115]!      
    • ## [1.4.1] - 2026-01-29   ### ✨ New Features - **Short Description**: Server owners can add a short tagline (up to 240 characters) on the server info page, under the "Online" status. It appears in the server list (By Votes) for VIP, Gold VIP, and Pinned servers so players see a brief summary at a glance.   ### 🔄 Improvements - **Server Info Page**: Description field is limited to 3000 characters with a character counter; the textarea is vertically resizable. A second **Save Changes** button was added at the bottom (after the description) for easier saving. - **Server Name**: In My Servers → Edit, the server name is read-only and can no longer be changed (avoids accidental changes and naming conflicts). - **Server Rows (By Votes)**: Short descriptions wrap correctly and no longer affect row height; long text is clipped to two lines so the list stays tidy and consistent.   ---
  • Topics

×
×
  • Create New...

Important Information

This community uses essential cookies to function properly. Non-essential cookies and third-party services are used only with your consent. Read our Privacy Policy and We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue..