Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package wciazchceumrzecaletrochemniej;
- import java.util.*;
- public class wciazchceumrzecaletrochemniej {
- public static void main(String[] args) {
- Scanner in = new Scanner (System.in);
- System.out.println("Program służy do przeliczania temperatury ze stopni Celsjusza na stopnie Kelwina lub Farenheita");
- System.out.println("Podaj temperaturę w stopniach Celsjusza. Do oddzielenia cz. całkowitej od cz. ułamkowej używaj przecinka.");
- double celsjusz = in.nextDouble();
- System.out.println("Wybierz, na jaką jednostkę chcesz przeliczyć podaną temperaturę.");
- System.out.println("1.Stopnie Kelwina");
- System.out.println("2.Stopnie Farenheita");
- System.out.println("Wybór to:");
- int co = 0;
- if (in.hasNextInt())
- co = in.nextInt();
- while (!(co==1 ||co==2)){
- System.out.println("Nie ma takiej opcji, spróbuj jeszcze raz.");
- in.nextLine();
- if (in.hasNextInt())
- co = in.nextInt();
- }
- if (co == 1)
- System.out.println("Podana temperatura wynosi w stopniach Kelwina " + celsjusz + 273.15);
- else if (co == 2)
- System.out.println("Podana temperatura wynosi w stopniach Farenheita " + 32 + (9/5)*celsjusz );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement