Új hozzászólás Aktív témák
-
sztikac
őstag
válasz
yossarian14
#11896
üzenetére
Huh, ha hiszed ha nem kb. 25x átfutottam ezt a kódrészletet és az agyam automatikusan így dolgozta fel:
public boolean equals(Person compared) {...}Köszi!
-
sztikac
őstag
Ha már MOOC... Van ez a kód:
public boolean equals(Object compared) {
// if the variables are located in the same position, they are equal
if (this == compared) {
return true;
}
// if the compared object is not of type Person, the objects are not equal
if (!(compared instanceof Person)) {
return false;
}
// convert the object into a Person object
Person comparedPerson = (Person) compared;
// if the values of the object variables are equal, the objects are equal
if (this.name.equals(comparedPerson.name) &&
this.age == comparedPerson.age &&
this.weight == comparedPerson.weight &&
this.height == comparedPerson.height) {
return true;
}
// otherwise the objects are not equal
return false;
}Itt nem igazán értem, hogy a type cast-ra (
Person comparedPerson = (Person) compared;) mi szükség van, hiszen a metódus már megkapja a compared objektumot
-
sztikac
őstag
-
sztikac
őstag
remélem nagyon kezdő kérdések is elférnek itt
Elkezdtem a MOOC.fi Java programozás kurzust és az egyik feladatnál elakadtam.
Illetve a feladatot magát meg tudtam oldani, az ellenőrzés mégis hibaüzenetet dob rá.
Ez lenne a kód:import java.util.Scanner;
public class InAHoleInTheGround {
public static void main(String[] args) {
printText();
}
public static void printText() {
Scanner scanner = new Scanner(System.in);
System.out.println("Give numbers:");
int sum = 0;
int count = 0;
int even = 0;
int odd = 0;
while (true) {
int number = Integer.valueOf(scanner.nextLine());
if (number == -1) {
break;
}
sum += number;
count++;
if (number % 2 == 0) {
even++;
} else {
odd++;
}
}
System.out.println("Thx! Bye!");
if (count != 0 && sum != 0) {
System.out.println("Sum: " + sum);
System.out.println("Numbers: " + count);
System.out.println("Average: " + 1.0 * sum / count);
System.out.println("Even: " + even);
System.out.println("Odd: " + odd);
}
}
}Tudnátok segíteni, mi lehet a gond?
Új hozzászólás Aktív témák
A topicot kiemeltem. Valaki nem akar egy nyitó hsz-t írni?:))
- Motoros topic
- PlayStation 5
- D1Rect: Nagy "hülyétkapokazapróktól" topik
- World of Tanks - MMO
- Battlefield 6
- Tőzsde és gazdaság
- AMD K6-III, és minden ami RETRO - Oldschool tuning
- Százmilliárd dolláros AI-fegyverkezésbe kezdett az Amazon és a Google
- iPhone topik
- Crimson Desert - Középpontban a harcrendszer és a karakterfejlődés
- További aktív témák...
- Üzletből, garanciával, Új Lenovo ThinkPad X1 Carbon Gen 12 Ultra 7 155u/32GBRAM/1TB SSD/OLED kijelző
- ÚJ BONTATLAN Apple Macbook Air 15,3 M4 10C CPU/10C GPU/16GB/256GB - Égkék - HUN - mc7a4mg/a 3 év gar
- iPhone 15 Pro 512GB Natural Titanium Makulátlan, garanciális, Apple Store vásárlás
- 6 HÓ GAR!! Xiaomi Mi Note 10 Lite 6GB/64GB
- HTC One M8 801n 32GB retró!
- Bomba ár! Lenovo ThinkPad T460s - i5-6GEN I 8GB I 192GB SSD I 14" FHD I Cam I W11 I Garancia!
- DJI mini 3 drón display unit
- Fujitsu Esprimo D7011 Intel i7-11700 16GB 512GB 1 év garancia
- FIFA 16 Playstation 4
- HP 14 Elitebook 640 G10 FHD IPS i5-1345U vPro 10mag 16GB 512GB SSD Intel Iris XE Win11 Pro Garancia
Állásajánlatok
Cég: PCMENTOR SZERVIZ KFT.
Város: Budapest
Cég: Central PC számítógép és laptop szerviz - Pécs
Város: Pécs



