Advertisement
Guest User

Untitled

a guest
Feb 28th, 2020
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. package firstTest;
  2.  
  3. public class HelloWorld {
  4.  
  5. public static void main(String[] args) {
  6. System.out.println("Hello world!");
  7. String[] langs;
  8. langs = new String[]{"C", "C++", "C#", "Python", "Go", "Rust", "JavaScript", "PHP", "Swift", "Java"};
  9. int n = randGenerate();
  10. n = calcN(n);
  11. n = digitSum(n);
  12. System.out.printf("Willy-nilly, this semester I will learn " );
  13. for(int i = 0; i < langs.length; i++) {
  14. System.out.printf("\"%s\" ",langs[i]);
  15. }
  16.  
  17. }
  18.  
  19. public static int randGenerate() {
  20. int n = (int) (Math.random() * 1_000_000);
  21. System.out.printf("n: %d\n", n);
  22. return n;
  23.  
  24. }
  25. public static int calcN(int n) {
  26. n = n * 3;
  27. byte b = (byte) 10101;
  28. int h = 0xFF;
  29. n = n + (int) b + h;
  30. n = n * 6;
  31. System.out.printf("The new n: %d\n", n);
  32. return n;
  33. }
  34.  
  35. public static int digitSum(int n) {
  36. int aux, sum;
  37.  
  38. while(n > 9) {
  39. sum = 0;
  40. while(n != 0)
  41. {
  42. aux = n % 10;
  43. sum = sum + aux;
  44. n = n / 10;
  45. }
  46. n = sum;
  47. }
  48.  
  49. System.out.printf("Sum of digits: %d\n", n);
  50.  
  51. return n;
  52. }
  53.  
  54.  
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement