Advertisement
Guest User

Java awesomeshit

a guest
Oct 27th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.22 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class Main {
  3.  
  4.     public static void main(String[] args) {
  5.         System.out.println("------------------4---------------------------");
  6.         int wynik = 0;
  7.         String str;
  8.         int size;
  9.         Scanner klawiatura = new Scanner(System.in);
  10.         System.out.print("Wpisz liczbe: ");
  11.         str = klawiatura.nextLine();
  12.         size = str.length();
  13.         System.out.println("Ilosc liczb w ciągu: " + size);
  14.         char[] podzielone = str.toCharArray();
  15.  
  16.         for(int i=0; i<size; i++){
  17.             int x = Character.getNumericValue(podzielone[i]);
  18.            wynik = wynik + x;
  19.         }
  20.  
  21.         System.out.println("Suma wpisanej liczby to: " + wynik);
  22.  
  23.         System.out.println("--------------------5-----------------------");
  24.  
  25.         Scanner klawiaturaa = new Scanner(System.in);
  26.         System.out.print("Wpisz liczbe: ");
  27.         double liczba = klawiaturaa.nextDouble();
  28.         double x = liczba - Math.floor(liczba);
  29.         if(x >= 0.5){
  30.             System.out.println("Liczba zaokrąglona: " + Math.ceil(liczba));
  31.         } else {
  32.             System.out.println("Liczba zaokrąglona: " + Math.floor(liczba));
  33.         }
  34.  
  35.         System.out.println("--------------------6-----------------------");
  36.  
  37.         Scanner klawiaturaaa = new Scanner(System.in);
  38.         System.out.print("Wpisz pierwsza liczbe: ");
  39.         int liczbaa = klawiaturaaa.nextInt();
  40.         System.out.print("Wpisz drugą liczbe: ");
  41.         int liczbaaa = klawiaturaaa.nextInt();
  42.         int calosc = liczbaa/liczbaaa;
  43.         int reszta = liczbaa%liczbaaa;
  44.  
  45.         if(reszta >0){
  46.             System.out.println("Wynik to: " + calosc + "." + reszta);
  47.         } else {
  48.             System.out.println("Wynik to: " + calosc);
  49.         }
  50.  
  51.         System.out.println("--------------------7-----------------------");
  52.  
  53.         Scanner klawiaturaaaa = new Scanner(System.in);
  54.         System.out.print("Wpisz ile sekund temu słyszałeś uderzenie pioruna: ");
  55.         float liczbaaaa = klawiaturaaaa.nextFloat();
  56.         float blyskawica = liczbaaaa * 330;
  57.         System.out.println("Wyładowanie atmosferyczne bylo oddalone od Ciebie o: " + blyskawica + " metrów:");
  58.             }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement