Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package firstTest;
- public class HelloWorld {
- public static void main(String[] args) {
- System.out.println("Hello world!");
- String[] langs;
- langs = new String[]{"C", "C++", "C#", "Python", "Go", "Rust", "JavaScript", "PHP", "Swift", "Java"};
- int n = randGenerate();
- n = calcN(n);
- n = digitSum(n);
- System.out.printf("Willy-nilly, this semester I will learn " );
- for(int i = 0; i < langs.length; i++) {
- System.out.printf("\"%s\" ",langs[i]);
- }
- }
- public static int randGenerate() {
- int n = (int) (Math.random() * 1_000_000);
- System.out.printf("n: %d\n", n);
- return n;
- }
- public static int calcN(int n) {
- n = n * 3;
- byte b = (byte) 10101;
- int h = 0xFF;
- n = n + (int) b + h;
- n = n * 6;
- System.out.printf("The new n: %d\n", n);
- return n;
- }
- public static int digitSum(int n) {
- int aux, sum;
- while(n > 9) {
- sum = 0;
- while(n != 0)
- {
- aux = n % 10;
- sum = sum + aux;
- n = n / 10;
- }
- n = sum;
- }
- System.out.printf("Sum of digits: %d\n", n);
- return n;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement