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

    • NEW SEASON 2025     GRAND OPENING 31.01.2025 Dear players, we would like present you the new season of the L2Exoplanet server. The new server will be rate x10 with alot new updates & fixes. We promise you the best High Five server with big community and balanced economy. Our project consists team of enthusiasts who love Lineage 2 and we would like invite to this iconic game.     GRAND OPENING:  31.01.2025 at 20:00 GMT+1 BETA TEST:   24.01.2025    Client: High Five Rates: x10   Website: https://l2exoplanet.net Facebook: https://www.facebook.com/L2-Exoplanet-106811564103836 Discord: https://discord.gg/4fzhW7ZSPc      
    • NEW SEASON START 31.1.2025       GRAND OPENING:  31.01.2025 at 20:00 GMT+1 BETA TEST:   24.01.2025    Client: High Five Rates: x10   Website: https://l2exoplanet.net Facebook: https://www.facebook.com/L2-Exoplanet-106811564103836 Discord: https://discord.gg/4fzhW7ZSPc       Game Rates    Experience: x10  Skill Points: x10  Adena: x8  Drop: x8  Spoil: x8  Quest: x5  Raid Boss Drop: x5  Fame: x2  Epaulette: x8  Manor: x8  MW Craft Chance: 6%  Key-Matherial-Recepie: x16    Safe Enchant: +3  Maximum Enchant: +16  Normal Scroll Chance: 60%  Blessed Scroll Chance: 63%  Attribute Stone Chance: 50%  Attribute Crystal Chance: 30%      Game Settings    Multibox - 3 game clients per HWID  Autoloot  Autolearn Skills  NPC Buffer  Buff Slots (24+4/12)  Buff Duration (2h)  Olympiad Period 7days (new heroes appear every monday)  Seven Signs Period  Class Transfer for Adena  Max Sub-Class 3  Sub-Class Max Level 85  Essence Interface  Champions System  Vote Reward System  Dayli Reward System  PC Points Reward (500PC = 1 Donate Coin)      Epic Bosses Respawn Times     Queen Ant:  24 Hours +/- 4 Hours   Beleth: 2 Days +/- 8 Hours   Baium: 2 Days +/- 8 Hours   Antharas: 3 Days +/- 8 Hours   Valakas:  3 Days +/- 8 Hours     Instance Info     Normal Freya = 6 Players   Hard Freya = 12 Players   Frintezza = 6 Players   Zaken 83 Day = 6 Players   Zaken 60 Day = 6 Players   Zaken Nightly = 6 Players   Tiat = 6 Players   Beleth = 12 Players
    • i think u need edit server files side too... bcs for interlude missing cmd for this set
    • Hi. I'm trying to rewrite the Lineage 2 interlude interface so that the screen displays information that, for example, the “Curse Gloom” debuff has entered and that it displays what skill has been resisted (there is only general information). Is it possible to do this?
    • OPENING ON MARCH 21 AT 18:00 GMT+1 Airin Server — a journey from the classic Chronicle 1 to the epic Chronicle 5, followed by a world merge with the Teon server. We are creating a unique gaming experience where each era unfolds gradually. From your first steps to battles with epic bosses, from the importance of every equipment grade to the significance of every location. Progressive Chronicles — your journey through history. Limits: 1 client per person Rates: Epic drop chance: x1 Quest drop chance: x1 Raid drop chance: x2 Adena (dynamic): x3~ (x1 for high-level) EXP\SP: x2-x3 Drop chance: x2-x3 Spoil chance: x2-x3 Quests A-grade: x1-x3 Quests S-grade: x1-x2 Welcome to Elmorelab.com!
  • Topics

×
×
  • Create New...