Du hast übrigens nur einen kleinen fehler gamacht 😀
nextLine
Advances this scanner past the current line and returns the input that was skipped. This method returns the rest of the current line, excluding any line separator at the end. The position is set to the beginning of the next line.
Since this method continues to search through the input looking for a line separator, it may buffer all of the input searching for the line to skip if no line separators are present.
statt:
next
Returns the next token if it matches the specified pattern. This method may block while waiting for input to scan, even if a previous invocation of hasNext(Pattern) returned true. If the match is successful, the scanner advances past the input that matched the pattern.
so funktionierts:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | import java.util.Scanner; public class PhysikTest { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("Welchen Physikalischen Wert suchen sie?"); String Gesucht = input.next(); if (Gesucht.equals("v")){ System.out.print("Zeiteinheit: "); String Zeiteinheit = input.next(); System.out.print("Zahlenwert der Zeit: "); int Zeit = input.nextInt(); System.out.print("Streckeneinheit: "); String Streckeneinheit = input.next(); System.out.print("Wert der Streckeneinheit: "); int Strecke = input.nextInt(); System.out.print(Geschwindigkeit(Strecke,Zeit)); System.out.println( Streckeneinheit + "/" + Zeiteinheit); } else{ System.out.println("Error"); } } public static int Geschwindigkeit(int s, int t) { int v = s / t; return v; } } |
–> echte profis hier im forum