christieeveleigh0@gmail.com
My First Dive Into Java

One of my top career goals for this year was to learn to program is Java. I had to push myself to get started, but eventually I read through a very long and detailed Java syntax cheat sheet. It taught me a lot and I decided to write my first program to learn how the structure of a Java program works. Today I’m going to play around with lists!

This simple program takes in 6 integers from the user as input and stores them into an empty list. The list is then printed out. We use Java’s .size() method to print out how many numbers were entered into the list. We also perform a basic sum on the list to add up all of the numbers and print out the result. As I get more familiar with Java, I’ll continue to add to this program. Lists are fun!

import java.util.Scanner;
import java.util.ArrayList;

public class QuickStart {
    static ArrayList<Integer> inputs = new ArrayList<Integer>(); // Creating an empty list
    public static void main(String[] args) {
        Scanner in = new Scanner (System.in); // Getting input from the user
        System.out.println("Enter 6 numbers"); 
        int i = 1; // Counter to repeat the While look 6 times
        while(i <= 6) { // Input for 6 numbers
            i += 1;
            inputs.add(in.nextInt()); // Adding the input to the list
        }

        printList();
        sizeOf();
        sumOf();
    }

    public static void printList() { // Prints out the list of numbers entered
        System.out.println(inputs);
    }

    public static void sizeOf() { // Prints out how many numbers are in the list
        System.out.println(inputs.size());
    }

    public static int sumOf() { // Work out the sum of the list of inputs
        int sum = 0;
        for (int i: inputs) {
            sum += i;
        }
        System.out.println(sum);
        return sum;
    }
}

I quite enjoyed my first dive into Java. While I’m used to programming in Python, I didn’t find the syntax changes as challenging as I was worried about because of some prior experience with C.

Check out my Github.

© Christie Eveleigh Marx 2020

× How can I help you?