Latest from community today
function helloWorld() {
console.log('Hello, World');
}
helloWorld();
def say_hello():
print ('Hello, World')
for i in range(5):
say_hello()
def primenumber(n):
if n%2==0:
print("prime number")
else:
print("odd number")
primenumber(60)
List1=['Bangalore','delhi','UP','MP']
update_dict=dict(enumerate(List1))
print(update_dict)
j="*"
for i in range(8):
print(j*i)
const arr = [[2], [3,[4]],"silly" ,[[[5,6],[7]]],[
["Cat", "Dog", "Quokka", "Possum"],
["Quokka"],
["Quokka", "Elephant", "Giraffe"],
"Cat", "Possum"
]];
//console.log(arr.flatMap((x)=>x));
console.log(arr.flat(4));
function checkPalindrome(data) {
const original = (data).toString().toLowerCase();
const updated = original.split('').reverse('').join('');
return original === updated ?? false;
}
console.log(checkPalindrome(12321));
console.log(checkPalindrome('aha'));
// 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));
}
}
}
for i in range(5):
print("Hello,world")
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)
}
}