aquaballoon

Java - Useful code

Mar 20th, 2013
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.66 KB | None | 0 0
  1. // String Input 1 //
  2. InputStreamReader isr = new InputStreamReader(System.in);
  3. BufferedReader in = new BufferedReader(isr);
  4. String str;
  5. str = in.readLine();
  6. System.out.println(str);
  7.  
  8. // String Input 2 //
  9. Scanner scan = new Scanner(System.in);
  10. String str = scan.nextLine();
  11. System.out.println(str);
  12.  
  13. // if String equals //
  14. if(str.equals("apple"))
  15.  
  16. // Converting to Int //
  17. int num = Integer.parseInt(str);
  18.  
  19. // Random number //
  20. Random r = new Random();
  21. int randomNum = Math.abs(r.nextInt() % 3); // 0 -> 2
  22.  
  23. // Formula for percentage //
  24. DecimalFormat fmt = new DecimalFormat("###.#%");
  25. System.out.println(fmt.format(30.0/80.0));
  26.  
  27. -------------> 37.5%
Advertisement
Add Comment
Please, Sign In to add comment