Click here to Skip to main content
16,022,332 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
import java.util.Scanner;
/*Türkçe = 3.3
Matematik = 3.3
Sosyal Bilimler = 3.4
Fen Bilimleri = 3.4*/

public class Hesaplama{
    
    public void tythesapla(Double sayı1, Double sayı2, Double sayı3, Double sayı4){
    try(Scanner scanner = new Scanner(System.in)){
        Yks_puan puanım = new Yks_puan(sayı1,sayı2,sayı3,sayı4);
        System.out.print("Türkçe netiniz : ");
        sayı1 = scanner.nextDouble();
        scanner.nextLine();
        System.out.print("Matematik netiniz : ");
        sayı2 = scanner.nextDouble();
        scanner.nextLine();
        System.out.print("Sosyal netiniz : ");
        sayı3 = scanner.nextDouble();
        scanner.nextLine();
        System.out.print("Fen netiniz : ");
        sayı4 = scanner.nextDouble();
        scanner.nextLine();
        puanım.setTürkçe(sayı1); puanım.setMatematik(sayı2); puanım.setSosyal(sayı3); puanım.setFen(sayı4);
        System.out.println("Tyt puanınız hesaplanıyor ...");
        Double sonuç = 100 + (sayı1*3.3) + (sayı2*3.3) + (sayı3*3.4) + (sayı4*3.4);
        System.out.println("Tyt ham puanınız : " +  sonuç);
    }
    }
    import java.util.Scanner;

public class Hesaplama2 {
    
    public void aythesapla(Double sayı1 , Double sayı2, Double sayı3, Double sayı4,
    Double sayı5, Double sayı6, Double sayı7, Double sayı8, Double sayı9){
        try(Scanner scanner = new Scanner(System.in)){
            Yks_puan puanım = new Yks_puan(sayı1, sayı2, sayı3, sayı4, sayı5, sayı6, sayı7, sayı8, sayı9);
            System.out.print("Lütfen bölümünüzü girin : ");
            String bölüm = scanner.nextLine();
            if(bölüm.equals("Sayısal") || bölüm.equals("sayısal") ||
            bölüm.equals("sayisal") || bölüm.equals("Sayisal")){
                //Matematik fizik kimya biyoloji
                System.out.print("Matematik netiniz : ");
                sayı1 = scanner.nextDouble();
                System.out.print("Fizik netiniz : ");
                sayı2 = scanner.nextDouble();
                System.out.print("Kimya netiniz : ");
                sayı3 = scanner.nextDouble();
                System.out.print("Biyoloji netiniz : ");
                sayı4 = scanner.nextDouble();
                puanım.setMat2(sayı1); puanım.setFizik(sayı2); puanım.setKimya(sayı3); puanım.setBiyoloji(sayı3);
                System.out.println("Ayt puanınız hesaplanıyor ...");
                Double sonuç = (sayı1*3) + (sayı2*2.85) + (sayı3*2.85) + (sayı4*3.07);
                System.out.println("Ayt ham puanınız : " + sonuç);

            }
        }
    }
}
<pre>

}
Java



What I have tried:

I checked the buffers and the error is like this 
TYT PUANI İÇİN ...
Türkçe netiniz : 10
Matematik netiniz : 10
Sosyal netiniz : 
10
Fen netiniz : 10
Tyt puanınız hesaplanıyor ...
Tyt ham puanınız : 234.0
AYT PUANI İÇİN ...
Lütfen bölümünüzü girin : Exception in thread "main" java.util.NoSuchElementException: No line found
        at java.base/java.util.Scanner.nextLine(Scanner.java:1677)
        at Hesaplama2.aythesapla(Hesaplama2.java:10)
        at Yks_hesap_programı.main(Yks_hesap_programı.java:8)

Posted
Comments
[no name] 6-Jul-24 7:46am    
Looking at the error it appears that the call to nextLine after printing "Lütfen bölümünüzü girin : ", is failing because there is no more input to read.

1 solution

Start by looking at the error message - it gives you a lot of information if you know how to read it. This may help: How to Write Code to Solve a Problem, A Beginner's Guide Part 2: Syntax Errors[^] - it's based around compiler errors, but the error message format for run time errors is much the same.
Your error is saying that a NoSuchElementException occurred (which you already know) in the file Hesaplama2.java on line 10. So edit that file, and use CTRL+G to go to that line (most editors support that shortcut) and find out exactly which bit of code is causing the error. We can't do that - we can't be sure which line in which file it matches!

When you know that, you can start looking to find out why it's happening - and the debugger is your friend here! Put a breakpoint on the first line of the method, and run your app. When it reaches the breakpoint, the debugger will stop, and hand control over to you. You can now run your code line-by-line (called "single stepping") and look at (or even change) variable contents as necessary (heck, you can even change the code and try again if you need to).
Think about what each line in the code should do before you execute it, and compare that to what it actually did when you use the "Step over" button to execute each line in turn. Did it do what you expect? If so, move on to the next line.
If not, why not? How does it differ?
Hopefully, that should help you locate which part of that code has a problem, and what the problem is.
This is a skill, and it's one which is well worth developing as it helps you in the real world as well as in development. And like all skills, it only improves by use!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900