Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. public class Main {
  2.  
  3. public static void main(String[] args) {
  4.  
  5.  
  6.  
  7. ArrayList<TelevisioOhjelma> ohjelmat = new ArrayList<>();
  8. Scanner lukija = new Scanner(System.in);
  9.  
  10.  
  11.  
  12. while (true) {
  13.  
  14. System.out.println("Nimi:");
  15. String nimi = lukija.nextLine();
  16. System.out.println("Pituus:");
  17. int pituus = Integer.valueOf(lukija.nextLine());
  18.  
  19. if (nimi.isEmpty()) {
  20. break;
  21. }
  22.  
  23.  
  24. ohjelmat.add(new TelevisioOhjelma(nimi, pituus));
  25. }
  26.  
  27. System.out.println("Ohjelman maksimipituus?");
  28. int maksimi = Integer.valueOf(lukija.nextLine());
  29.  
  30. for (TelevisioOhjelma TelevisioOhjelma: ohjelmat) {
  31. if (TelevisioOhjelma.getPituus() <= maksimi) {
  32. System.out.println(TelevisioOhjelma.toString());
  33. }
  34. }
  35.  
  36.  
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement