Skip to content

Instantly share code, notes, and snippets.

View viveknarang's full-sized avatar
🇨🇦
O Canada!

Vivek Narang viveknarang

🇨🇦
O Canada!
  • Toronto, Canada
View GitHub Profile
public void printTicket(int destinationNumber) // method signature, method name, public - accessibility
// of the method from external classes
{
if (destinationNumber == 1) {
if (balance < price1) {
System.out.println("Please insert " + (price1 - balance) + " more dollars.");
} else {
import java.util.Scanner;
public class Program {
public static void main(String[] args) {
//Declare person objects here
Person person1 = new Person("Nikhil Dewars",40 , "MIS", 3.9);
Person person2 = new Person("Mark Budweiser",23 , "MIS", 3.2);
Person person3 = new Person("Craig Appletons",25 , "MIS", 3.0);
public class Session1 {
public static void main(String[] args) {
System.out.println("A");
System.out.println("B");
int total = sum(5, 10);
System.out.println("The sum is " + total);
}
import java.util.Scanner;
public class NegativeOrPositive {
public static void main (String [] args) {
String condStr;
int userVal;
userVal = -9;
condStr = (userVal >= 0)?"non-negative":"negative";
import java.util.Scanner;
public class CharMatching {
public static void main (String [] args) {
String userInput = "";
char firstLetter = '-';
userInput = "banana";
firstLetter = 'b';
public class Portfolio {
public static void main(String[] args) {
double portfolioValue = 0.0;
Stock appl = new Stock("Apple", 1000, 50.0);
Stock ge = new Stock("General Electric", 1001, 51.0);
Stock gm = new Stock("General Motors", 2001, 25.0);
Stock amzn = new Stock("Amazon", 10000, 500.0);
import java.util.Scanner;
public class BillCalc {
public static void main(String[] args) {
//Declare variables to be used (billAmount, nosOfDiners)
int billAmount = 0;
int nosOfDiners = 0;
Scanner scnr = new Scanner(System.in);
// Created by Vivek Narang, 1/3/2018 4:33 AM EST
// A JavaScript function that takes in two arguments (Hex color codes) and returns the average of those ...
function avgColor(c1, c2) {
// Extract the R/G/B parts from the first argument ...
var c111 = parseInt(c1.substr(4, 2), 16);
var c121 = parseInt(c1.substr(2, 2), 16);
var c131 = parseInt(c1.substr(0, 2), 16);
import java.util.Arrays;
public class Compute {
int[] numbers;
int min = Integer.MAX_VALUE;
int max = Integer.MIN_VALUE;
double mean = 0.0;
public Compute(int[] numbers) {
public class Main {
public static void main(String[] args) {
int[][] arr = { { 0, 5 }, { 10, 25 }, { 30, 10 }, { 30, 5 }, { 299, 5 }, { 299, 1 } };
try {
new Engine(arr);
} catch (Exception e) {
e.printStackTrace();
}
}