# All# python# wedfg# scope variable# interview# lexical environment# javascript# #algorithm# hoisting# good# print# java# coding shortcut# competitive coding# shorthand# loop tricks# sample# #c# gambling# primitives# algoritms# arrow-functions# javascriptintro# usefullinks# technical round# project# beetroot# reverse# array# copy# collection# test# i am printing hello world# #class# #js# #interview# map# lodash# scoping# async# prime numbers# weather app# easy way to remove duplicates# # #javascript# pho# possible ways of calculator app# var a = 10 function f(){ console.log(a) } f(); console.log(a);# gg# as# palindrome# hello world basic intro# #python# pattern program# nodejs

Latest from community today

// Online Java Compiler
// Use this editor to write, compile and run your Java code online
import java.util.*;
class HelloWorld {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        
        // all four possible moves
        int[][] moves = new int[4][2];
        moves[0] = new int[]{0,1};
        moves[1] = new int[]{1,0};
        moves[2] = new int[]{0,-1};
        moves[3] = new int[]{-1,0};
        
        // define matrix
        int[][] mat = new int[N][N];
        int k = 1;
        
        int direction = 0;
        int x = 0 , y = 0;
        
        for(int i = 0 ; i < N*N ; i++) {
            
            //assign and take a step
            mat[x][y] = k;
            k++;
            x += moves[direction][0];
            y += moves[direction][1];
            
            // check boundaries and already visited
            if (0 <= x && 0<= y && x < N && y <N && mat[x][y] == 0) {
                continue;
            } else {
                x -= moves[direction][0];
                y -= moves[direction][1];
                
                //change direction
                direction = direction == 3 ? 0 : direction +1;
                x += moves[direction][0];
                y += moves[direction][1];
            }
            
            //change k
        }
        
        for(int[] arr : mat) {
            System.out.println(Arrays.toString(arr));
        }
    }
}
import Foundation

 // PRINT PRIME NUMBERS USING SWIFT
        
        for n in 2...100 {
            if n % 2 == 0 && n < 3{
                print(n)
            } else if n % 3 == 0 && n > 6 {
            } else if n % 5 == 0 && n > 5 {
            } else if n % 7 == 0 && n > 7{
            } else if n % 2 == 1 {
                print(n)
            }
        }

Featured content