Advertisement
Guest User

Untitled

a guest
Nov 17th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. package wciazchceumrzecaletrochemniej;
  2. import java.util.*;
  3. public class wciazchceumrzecaletrochemniej {
  4.  
  5. public static void main(String[] args) {
  6. Scanner in = new Scanner (System.in);
  7. System.out.println("Program służy do przeliczania temperatury ze stopni Celsjusza na stopnie Kelwina lub Farenheita");
  8. System.out.println("Podaj temperaturę w stopniach Celsjusza. Do oddzielenia cz. całkowitej od cz. ułamkowej używaj przecinka.");
  9. double celsjusz = in.nextDouble();
  10. System.out.println("Wybierz, na jaką jednostkę chcesz przeliczyć podaną temperaturę.");
  11. System.out.println("1.Stopnie Kelwina");
  12. System.out.println("2.Stopnie Farenheita");
  13. System.out.println("Wybór to:");
  14. int co = 0;
  15. if (in.hasNextInt())
  16. co = in.nextInt();
  17. while (!(co==1 ||co==2)){
  18. System.out.println("Nie ma takiej opcji, spróbuj jeszcze raz.");
  19. in.nextLine();
  20. if (in.hasNextInt())
  21. co = in.nextInt();
  22. }
  23. if (co == 1)
  24. System.out.println("Podana temperatura wynosi w stopniach Kelwina " + celsjusz + 273.15);
  25. else if (co == 2)
  26. System.out.println("Podana temperatura wynosi w stopniach Farenheita " + 32 + (9/5)*celsjusz );
  27.  
  28. }
  29.  
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement