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 :)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Posts

    • Faltan demasiados archivos,  y lógicas en clases claves como L2pcInstance, entre otras. si bien muchas cosas están y el flujo es valorable.  Gracias por tu esfuerzo es bastante... pero realmente no esta completo el código, falta que subas todas las modificaciones en clases colaterales... podrías intentar subir un diff de todo el mod  completo de tu pack y bueno ahí si que cada uno adapte... pero faltan muchas cosas, dudo que haya gente que lo haya echo funcionar con esto... 
    • I know people who have fully bypassed and reversed AAC. One day, they might even release the full source code, but for now, they’re still making money off it. I won’t name anyone, but it’s clear that there aren’t any truly solid anticheats for Lineage2. As I’ve said before, kernel level anticheats are the only real solution. Anything that runs as Internal and injects gets flagged, and your account ends up getting kicked or banned. That’s just how most games handle it nowadays. To TL;DR the whole thing cheating will always exist because there are people out there smart enough to bypass any protection and run private cheats. Public cheats are always detected eventually, so I don’t see any point in buying AAC, especially when they claim it blocks adr, which simply isn’t true.
    • 🌐 Website: https://l2adonis.com 📅 GRAND OPENING: July 18, 2025 – 20:00 (UTC+2) 💬 Discord: https://discord.com/invite/tZBj8JxAwx 🚫 No auto-farm • No auto-macro • No pay-to-win • No custom   Some Basic Info's (More detalied info's on website)  EXP/SP: x25  Adena: x15  Drop: x15  Spoil: x15  Seal Stones: x15  Raid Boss Drop: x10  Epic Boss Drop: x1  Manor: x10  Safe Enchant: +4  Max Enchant: +16  Normal Scroll Chance: 50%  Blessed Scroll Chance: 66% (If enchant fail item remain +4)  Buff Slots (30+4 extra with Divine Inspiration)  Dances/Songs Slots 14  Auto-learn skills  ⚔️ Real PvP • Real Progression • Retail-like experience JOIN NOW and relive the real L2 experience!
    • Discord         :  utchiha_market Telegram        : https://t.me/utchiha_market Auto Buy Store  : https://utchihamkt.mysellauth.com/ Not sure if we’re legit? Check Our server — real reviews, real buyers https://discord.gg/uthciha-servicess  | https://campsite.bio/utchihaamkt
    • Looking for a Developer – Lineage II Interlude (Vanganth Files)   I’m seeking a developer to collaborate on a project based on Vanganth Interlude files.   Important: Applicants with a bad attitude, lack of respect, or unwillingness to work will be immediately rejected. Payment: Hourly rate, not per task. Contact: Please reach out to me via PM.
  • Topics

×
×
  • Create New...

AdBlock Extension Detected!

Our website is made possible by displaying online advertisements to our members.

Please disable AdBlock browser extension first, to be able to use our community.

I've Disabled AdBlock