0
public void hesapEkle() {
    System.out.println("Oluşturmak istediğiniz hesap türünü seçiniz:");
    System.out.println("1. Vadeli Hesap");
    System.out.println("2. Vadesiz Hesap");
    Scanner getInput = new Scanner(System.in);
    int acilacakHesapTuru = getInput.nextInt();
    getInput.close();

    String hesapTuru;
    System.out.println("Hesap turu girin (Maas / Normal):");

    Scanner getInput1 = new Scanner(System.in);
    hesapTuru = getInput1.nextLine();
    getInput1.close();

    if((hesapTuru != "Maas") && (hesapTuru != "Normal")) {
        System.out.println("Girilen hesap turu gecersiz oldugundan normal hesap olarak tanimlandi.");
        hesapTuru = "Normal";
    }
}

Hesap turu girin (Maas / Normal)

Exception in thread "main" java.util.NoSuchElementException: No line found at Musteri.hesapEkle(Musteri.java:65)

Here is my output^^ Why can't i get another input except acilacakHesapTuru variable? ......................................................................................................................................................................................................................................................................................................................................................

Aytgg
  • 1
  • full output: ```[code block]Olusturmak istediginiz hesap turunu seciniz: 1. Vadeli Hesap 2. Vadesiz Hesap 2 Hesap turu girin (Maas / Normal) Exception in thread "main" java.util.NoSuchElementException: No line found at java.base/java.util.Scanner.nextLine(Scanner.java:1651) at Musteri.hesapEkle(Musteri.java:65) at Proje.main(Proje.java:7) ``` – Aytgg May 02 '23 at 23:56
  • `getInput.close();` you've closed the scanner, which will in turn close `System.in`, which is not something you want to do – MadProgrammer May 02 '23 at 23:59
  • `hesapTuru != "Maas"` is not how you compare `String`s in Java see [How do I compare strings in Java?](https://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java) for how it should be done – MadProgrammer May 03 '23 at 00:00
  • After `getInput.nextInt()`, add `getInput.nextLine();`, this will consume the dangling new line, so that when you do `hesapTuru = getInput.nextLine();` it won't return immediately (with an empty `String`) – MadProgrammer May 03 '23 at 00:02
  • i changed .nextLine(); to .next(); and it fixed. Thx for everyone. – Aytgg May 03 '23 at 00:15
  • But i have another question now. ```[code block] public static long createIBAN() { //Rastgele IBAN oluşturma. long createdIBAN = 0; Random rand = new Random(); for (int i = 0; i < 16; i++) { int randNum = rand.nextInt(9)+1; createdIBAN += Math.pow(10, i)*randNum; } return createdIBAN; } ``` This method return 0 everytime? Why? It should return 16digits random num – Aytgg May 03 '23 at 00:16
  • Just remember, `.next()` will split words on spaces, so if the user enters multiple words, you'll only get the first one – MadProgrammer May 03 '23 at 00:21
  • Returned `2224541622274355` for me – MadProgrammer May 03 '23 at 00:22
  • @MadProgrammer actually its better for me :). – Aytgg May 03 '23 at 00:28
  • @MadProgrammer weird, it's still returning 0 for me :/ – Aytgg May 03 '23 at 00:28
  • We'd need to see it used in context - but that's actually another question – MadProgrammer May 03 '23 at 00:29
  • yeah, but i can't create a new question within 90mins :( – Aytgg May 03 '23 at 00:32
  • `super(BankaHesap.createIBAN(), vadeliBakiye, hesapBilgisi, "Vadeli");` i'm using it like that and returns 0 but if i use it except a super tag it returns normal – Aytgg May 03 '23 at 00:33

0 Answers0