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 class FindSpaces {
public static void main (String [] args) {
String passCode = "";
passCode = " ";
for (int i = 0 ; i < passCode.length(); i++) {
if (passCode.charAt(i) == ' ') {
System.out.println("Space at " + i);
}
Execute:
> SELECT propCode, SUM(lineItemCost) FROM Preventative where SPRIORITY = 'Preventive Maint' group by propCode
+ ------------- + ---------------------- +
| propCode | SUM(lineItemCost) |
public class NestedLoops {
public static void main (String [] args) {
int numRows = 2;
int numCols = 3;
// Note: You'll need to declare more variables
/* Your solution goes here */
for (int i = 1 ; i <= numRows; i++) {
for(int j = 1 ; j <= numCols; j++) {
public class NestedLoop {
public static void main (String [] args) {
int userNum = 0;
int i = 0;
int j = 0;
/* Your solution goes here */
for (i = 0; i <= userNum; i++) {
for (j = 0; j < i; j++) {
System.out.print(" ");
import java.util.Scanner;
public class InsectGrowth {
public static void main (String [] args) {
int numInsects = 0;
numInsects = 8; // Must be >= 1
while(numInsects < 100) {
System.out.print(numInsects + " ");
import java.util.Scanner;
public class GrocerySorter {
public enum GroceryItem {GR_APPLES, GR_BANANAS, GR_JUICE, GR_WATER};
public static void main (String [] args) {
GroceryItem userItem = GroceryItem.GR_APPLES;
/* Your solution goes here */
if (userItem == GroceryItem.GR_APPLES || userItem == GroceryItem.GR_BANANAS) {
import java.util.Scanner;
public class SimonSays {
public static void main (String [] args) {
String simonPattern = "";
String userPattern = "";
int userScore = 0;
int i = 0;
userScore = 0;
public class StudentScores {
public static void main (String [] args) {
final int SCORES_SIZE = 4;
int[] oldScores = new int[SCORES_SIZE];
int[] newScores = new int[SCORES_SIZE];
int i = 0;
oldScores[0] = 10;
oldScores[1] = 20;
oldScores[2] = 30;
import java.util.Scanner;
public class FindMatchValue {
public static void main (String [] args) {
final int NUM_VALS = 4;
int[] userValues = new int[NUM_VALS];
int i = 0;
int matchValue = 0;
int numMatches = -99; // Assign numMatches with 0 before your for loop
import java.util.Scanner;
public class SumOfExcess {
public static void main (String [] args) {
final int NUM_VALS = 4;
int[] testGrades = new int[NUM_VALS];
int i = 0;
int sumExtra = -9999; // Assign sumExtra with 0 before your for loop
testGrades[0] = 101;