Advertisement
Guest User

Untitled

a guest
Jan 17th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.*;
  3. public class testi1 {
  4. public static void main( String [ ] args) {
  5.  
  6. Scanner lukija;
  7. lukija = new Scanner(System.in);
  8. double weight;
  9. double height;
  10. double age;
  11. String Carlicense;
  12.  
  13. System.out.print("How much is your weight: ");
  14. weight = lukija.nextDouble();
  15. System.out.print ("How much is your height: ");
  16. height = lukija.nextDoable();
  17. System.out.print ("How old are you: ");
  18. age = lukija.nextDouble();
  19.  
  20. // 1. Lisää kysely CarLicense muuttujan täyttämiseen
  21. //esim System.out.print ("Do you have car license? Answer as Yes or No. ");
  22. // CarLicense = lukija.next();
  23.  
  24. //2. Lisää asetetut arvot tulostukseen.
  25. // System.out.println ("Ikä"+ String.valueOf(age)); <- double tyyppinen muuttuja konvertoidaan string tyyppiseksi, jotta se
  26. // voidaan tulostaa käyttöliittymälle. CarLicense -muuttuja ei tarvitse konversiota ja sen lisäys
  27. // olisi seuraavanlainen System.out.println ("Pituus" + CarLicense);
  28. System.out.println ("Käyttäjän tiedot:");
  29. System.out.println ("Ikä" );
  30. System.out.println ("Paino" );
  31. System.out.println ("Pituus" );
  32.  
  33. //3. Korjaa if- lauseen vertailu.
  34. // if lauseen sulkujen () sisällä täytyy olla vertailu joka on arvoista riippuen tosi tai epätosi.
  35. // esimerkiksi if (CarLicense =="Yes") <- palauttaa tosi, jos CarLicense:n arvo on Yes
  36. // saman voi toteuttaa myös käyttämällä Objects.equals(CarLicense, "Yes") -metodia if ehdossa
  37. // esim if(Objects.equals(CarLicense, "Yes"))
  38.  
  39. if (CarLicense("Yes"){
  40. System.out.printIn("Sinulla on ajokortti: ");
  41. }else{
  42. System.out.printIn("Sinulla ei ole ajokorttia: "); }
  43. System.out.println();
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement