Skip to content

Instantly share code, notes, and snippets.

View karellism's full-sized avatar
:electron:
Educating myself

Karel Vanhelden karellism

:electron:
Educating myself
  • Karellism
  • karelvanhelden@gmail.com
View GitHub Profile
import java.io.*;
import java.util.Scanner;
public class MixedTypeInput {
public static void main(String[] args) {
double number;
Scanner in = new Scanner(System.in);
System.out.println("Enter your gross income: ");
@karellism
karellism / LocalHostName.java
Created December 30, 2015 01:27
LocalHostName.java
import java.net.InetAddress;
import java.net.UnknownHostException;
public class HostnameExample {
public static void main(String[] args) {
try {
InetAddress address = InetAddress.getLocalHost();
System.out.println("Hostname: " + address.getHostName());
} catch (UnknownHostException e) {
@karellism
karellism / Divisibility.java
Last active February 15, 2019 08:42
TRUE or FALSE is Divisible by 7?
/******************************************************************************
*
* Reads in two integer command-line arguments x and y and prints "true"
* if both are divisible by 7, and false otherwise.
*
* a % 7 is the remainder when you divide 7 into a. If the remainder
* is 0, then a is divisible by 7.
*
******************************************************************************/
@karellism
karellism / basic.c
Last active February 15, 2019 08:14
Simple C code template
#include <stdio.h>
int main(void) {
printf("Hello");
return 0;
}
@karellism
karellism / ArraysDeclaration.java
Last active February 28, 2019 12:33
2 ways how you can declare an Array in Java.
int intArray[]; //Declaring Array
intArray = new int[20]; //Allocating Memory To Array
int[] intArray = new int[20]; //Combining Both Statements In One Line
int[] intArray = new int[]{ 1,2,3,4,5,6,7,8,9,10 }; //Declaring A Literal Array
@karellism
karellism / InputScanner.java
Created February 15, 2019 08:40
How to get the user input using Scanner. Here the input is an integer that will be stored in int variable i.
Scanner sc = new Scanner(System.in);
int i = sc.nextInt();
@karellism
karellism / AddTwoArrays.cpp
Created February 17, 2019 07:36
Adding the Nth value of the first and second array and output their sum untill the limit is reached.
#include <iostream>
using namespace std;
main()
{
int first[20], second[20], c, n;
cout << "Enter the number of elements in the array ";
cin >> n;
@karellism
karellism / linkedlistexample.cpp
Created February 28, 2019 09:05
Linked list example in C/C++
// A linked list node
struct ListNode
{
int val;
struct ListNode *next;
};
@karellism
karellism / ListNode.java
Created February 28, 2019 09:07
Linked list example in Java
// Linked list class
class ListNode
{
// head of list
Node head;
// Node class
class Node
{
int val;
@karellism
karellism / linkedlistexample.py
Created February 28, 2019 09:08
Linked list example in Python
# Node class
class Node:
# Function to initialize the node object
def __init__(self, v):
self.val = v # Assign value
self.next = None # Initialize next as null
# Linked List class
class ListNode:
# Function to initialize the Linked List