0

Помогите исправить код джава . пишет что нет вывода.

import java.util.Scanner; class Main { public static void main(String[] args) { Scanner read = new Scanner(System.in); String name = read.nextLine(); int age = read.nextInt(); Student student = new Student(); student.name = name; student.setAge(age); System.out.println("Name: " + student.name); System.out.println("Age: " + student.getAge()); } } class Student { public String name; private int age; public int getAge() { return age; } public void setAge(int age) { if(age < 0){ System.out.println("invalid age ); this.age=0; } }

29th Nov 2022, 3:39 AM
Владислав
Владислав - avatar
1 Réponse
+ 1
in else part: Set the input age to the age of the student. like else this.age = age; edit: в другой части: Установите возраст ввода на возраст ученика. как еще this.age = возраст;
29th Nov 2022, 7:50 AM
Jayakrishna 🇮🇳