CodeGym
Promocja
Nauka
Kursy
Zadania
Ankiety & quizy
Gry
Pomoc
Harmonogram
Społeczność
Użytkownicy
Forum
Czat
Artykuły
Historie sukcesu
Aktywność
Opinie
Subskrypcje
Jasny motyw
Pytanie
  • Opinie
  • O nas
Start
Rozpocznij naukę
Rozpocznij naukę teraz
  • Wszystkie pytania
CodeGym/Pomoc w zadaniach Java/I got correct answer, but still does not pass validation....
Radek
Poziom 13
Gdynia
  • 24.01.2022
  • 507wyświetlenia
  • 4komentarze

I got correct answer, but still does not pass validation. I went through all previous hints. What is wrong in my code?

Pytanie o zadanie Zadanie nr 4 z konwersją typu int
Java Syntax,  Poziom 10,  Lekcja 4
Rozwiązane


Dodaj jedną konwersję typu, aby otrzymać następującą odpowiedź: dziewiec = 9
short liczba = 9;
char zero = '0';
int dziewiec = (zero + liczba);

Wymagania:
  • Program powinien wyświetlać tekst na ekranie.
  • Nie zmieniaj komendy wyświetlającej się na ekranie. Możesz jedynie dodawać do niej operatory rzutowania.
  • Metoda main() musi zawierać zmienną liczba typu short.
  • Metoda main() musi zawierać zmienną zero typu char.
  • Metoda main() musi zawierać zmienną dziewiec typu int.
  • Nie zmieniaj początkowej wartości zmiennych w trakcie inicjalizacji. Możesz jedynie dodawać operatory rzutowania.
  • Program powinien wyświetlać liczbę 9.
package pl.codegym.task.task10.task1004; /* Zadanie nr 4 z konwersją typu int */ public class Solution { public static void main(String[] args) { short liczba = 9; char zero = '0'; int dziewiec = zero + liczba; System.out.println((char) dziewiec); } }
0
Komentarze (4)
  • Popularne
  • Nowe
  • Najstarsze
Musisz być zalogowany aby dodać komentarz
Radek
Poziom 13 , Gdynia, Poland
27 stycznia 2022, 10:36
Yes. The bracket was the problem, thanks for your help :)
0
Gellert Varga
Poziom 23 , Szekesfehervar, Hungary
24 stycznia 2022, 13:50
I think your programme is absolutely right. It does the (char) type conversion, and that was the important point. The output of the program should be: 9 and this is perfectly fine in your program. Probably the problem for the checker machine is that you have removed the brackets from line 11, which is in the requirements: int dziewiec = (zero + liczba);
0
Guadalupe Gagnon
Poziom 37 , Tampa, United States
24 stycznia 2022, 14:27
Gellert is correct. When the task says to make one change (or, in some tasks, a very specific amount of changes) it will test that the code has not been modified other than what the task directions say. If that wasn't the case you could pass the task by just doing this:
public class Solution {
    public static void main(String[] args) {
        //short number = 9;
        //char zero = '0';
        //int nine = (zero + number);
        System.out.println('9');
    }
}
That would output the correct answer, but since the 'solve' modified code it was not supposed to it would not pass the validation. You should just reset the task and then add the correct code in without modifying any of the other code, that should pass it for you. Make sure to be careful in future tasks that you do not make this mistake again.
0
Kubalahit
Poziom 16 , Gdańsk, Polska
24 stycznia 2022, 10:09
Output should be "Nine = 9" and your's is just "9".
0
Nauka
  • Rejestracja
  • Kurs Java
  • Pomoc w zadaniach
  • Cennik
  • Składnia Javy
Społeczność
  • Użytkownicy
  • Artykuły
  • Forum
  • Czat
  • Historie sukcesu
  • Aktywność
  • Program partnerski
Firma
  • O nas
  • Kontakt
  • Opinie
  • Dla mediów
  • CodeGym dla EDU
  • FAQ
  • Wsparcie
CodeGymCodeGym to kurs online do nauki programowania w Javie od podstaw. Kurs idealny do opanowania Javy dla początkujących. Zawiera 1200+ zadań z natychmiastową weryfikacją oraz niezbędny zakres teorii podstaw Javy. Aby pomóc Ci w nauce, wprowadziliśmy zestaw funkcji motywacyjnych: quizy, projekty programistyczne, materiały o efektywnej nauce i poradnik kariery dla programisty Java.
Obserwuj nas
Język interfejsu
English Deutsch Español हिन्दी Français Português
Polski
বাংলা 简体中文 मराठी தமிழ் Italiano Bahasa Indonesia 繁體中文 Nederlands 日本語 한국어 Bulgarian Danish Hungarian Basa Jawa Malay Norwegian Romanian Swedish Telugu Thai Українська Filipino Turkish Azərbaycan Русский Vietnamese
"Programiści są tworzeni, nie rodzą się" © 2026 CodeGym
MastercardVisa
"Programiści są tworzeni, nie rodzą się" © 2026 CodeGym