# 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# # pho# possible ways of calculator app# var a = 10 function f(){ console.log(a) } f(); console.log(a);# gg# as

Latest from community today

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)
            }
        }

{
    public void polygon(int n, char ch) {
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                System.out.print(ch);
            }
            System.out.println("");
        }
    }
    
    public void polygon(int x, int y) {
        for (int i = 1; i <= x; i++) {
            for (int j = 1; j <= y; j++) {
                System.out.print('@');
            }
            System.out.println("");
        }
    }
    
    public void polygon() {
        for (int i = 1; i <= 3; i++) {
            for (int j = 1; j <= i; j++) {
                System.out.print('*');
            }
            System.out.println("");
        }
    }
    
    public static void main() {
        Poly obj = new Poly();
        obj.polygon(2, 'o');
        System.out.println("");
        obj.polygon(2, 5);
        System.out.println("");
        obj.polygon();
    }
}
{
    public void polygon(int n, char ch) {
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                System.out.print(ch);
            }
            System.out.println("");
        }
    }
    
    public void polygon(int x, int y) {
        for (int i = 1; i <= x; i++) {
            for (int j = 1; j <= y; j++) {
                System.out.print('@');
            }
            System.out.println("");
        }
    }
    
    public void polygon() {
        for (int i = 1; i <= 3; i++) {
            for (int j = 1; j <= i; j++) {
                System.out.print('*');
            }
            System.out.println("");
        }
    }
    
    public static void main() {
        Poly obj = new Poly();
        obj.polygon(2, 'o');
        System.out.println("");
        obj.polygon(2, 5);
        System.out.println("");
        obj.polygon();
    }
}

{
    public void polygon(int n, char ch) {
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                System.out.print(ch);
            }
            System.out.println("");
        }
    }
    
    public void polygon(int x, int y) {
        for (int i = 1; i <= x; i++) {
            for (int j = 1; j <= y; j++) {
                System.out.print('@');
            }
            System.out.println("");
        }
    }
    
    public void polygon() {
        for (int i = 1; i <= 3; i++) {
            for (int j = 1; j <= i; j++) {
                System.out.print('*');
            }
            System.out.println("");
        }
    }
    
    public static void main() {
        Poly obj = new Poly();
        obj.polygon(2, 'o');
        System.out.println("");
        obj.polygon(2, 5);
        System.out.println("");
        obj.polygon();
    }
}
{
    public void polygon(int n, char ch) {
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                System.out.print(ch);
            }
            System.out.println("");
        }
    }
    
    public void polygon(int x, int y) {
        for (int i = 1; i <= x; i++) {
            for (int j = 1; j <= y; j++) {
                System.out.print('@');
            }
            System.out.println("");
        }
    }
    
    public void polygon() {
        for (int i = 1; i <= 3; i++) {
            for (int j = 1; j <= i; j++) {
                System.out.print('*');
            }
            System.out.println("");
        }
    }
    
    public static void main() {
        Poly obj = new Poly();
        obj.polygon(2, 'o');
        System.out.println("");
        obj.polygon(2, 5);
        System.out.println("");
        obj.polygon();
    }
}
console.log('Tet3');
//variable in js
//var,let,const
var name='Anees';
var c;
var marks='90';
console.log(name,c,marks);
//////////////////////////////
var _city='Mumbai';
console.log(city)
const myname='Ahmad';
// myname = 'Happy';//can not do this (error)
console.log(myname);
const fruit='Apple';
///////////////////////////////
{
Let city ='Kanpur';
city = 'Lucknow';
console.log(city);
}
console.log(city);
import "./App.css"
import { useState } from "react"
const App=()=> {
  const [calc,setcalc]=useState("")  // this state updates all the clicked operators and integers
  const [res,setres]=useState("")   //this state updates result
  const ops=["/","*","+","-","."];
  const updcalc=(value)=>{
    if(ops.includes(value) && calc=== "" ||
    ops.includes(value) && ops.includes(calc.slice(-1))
    ){return}
   setcalc(calc+value)
    if(!ops.includes(value)){
      setres(eval(calc+value).toString())
    }
  }
const digits=()=>{
    let nums=[]
    for(let i=1;i<10;i++){
      nums.push(
        <button onClick={()=>updcalc(i.toString())} key={i}>{i}</button>
      )
    }
    return nums
  }
  const cal=()=>{
    setcalc(eval(calc).toString());
  }
  const del=()=>{
    if(cal == ''){
      return '0'
    }
    const value=calc.slice(0,-1)
    setcalc(value)
  }
  return (
    <div className="app">
      <div className="calculator">
        <div className="display">
          {res?<span>({res})</span>: ""}
          {calc}
        </div>
        <div className="operators"> 
        <button onClick={()=>updcalc("+")}>+</button>
        <button onClick={()=>updcalc("-")}>-</button>
        <button onClick={()=>updcalc("*")}>*</button>
        <button onClick={()=>updcalc("/")}>/</button>
        <button onClick={del}>DEL</button>
        </div>
        <div className="digits">
          {digits()}
        <button onClick={()=>updcalc("0")}>0</button>
          <button onClick={()=>updcalc(".")}>.</button>
        <button onClick={cal}>=</button>
</div>

      </div>
     
    </div>
  );
}

export default App;
/**
  Do not remove or modify below import statements.
  Any other import statment will not work.
**/
import React from 'react';
import ReactDOM from 'react-dom';
import axios from "axios";
/**
  To use functions like useState, useRef etc.
  destruct it like const { useState, useRef } = React
**/

const App = () => {
  const [city, setcity] = React.useState("");
  const [data,setdata]=React.useState({
    description:"",
    temp:0,
    sunrise:0,
    country:""
  });
  
  const handleClick=()=>{
    axios.get(`http://api.openweathermap.org/data/2.5/weather?q=${city}&appid=8dd666c3c64eee59ee7fb3c6de133362
`).then((res)=>{setdata({
      description:res.data.weather[0].description,
    temp:res.data.main.temp,
    sunrise:res.data.sys.sunrise,
    country:res.data.sys.country
    })})
  }
  return (
    <>
      <div>
          <h1>Weather App</h1>
       <input type="text" placeholder="Enter City" value={city} onChnage={(e)=>{setcity(e.target.value)}}></input>
          <button type='submit' onClick={handleClick} >
              Click 
          </button>
       
      </div>
      
   //Show component
      <Show text={data}></Show>
     
      </>
  );
}
//create another component to display this data by passing props and render in app component.
const Show=({text})=>{
  return(
    <div>
     <div>
      <h4>Description</h4>
       <p>{text.description}</p>
      </div>
      <div>
      <h4>Temperature</h4>
       <p>{text.temp}</p>
      </div>
      <div>
      <h4>Sunrise</h4>
       <p>{text.sunrise}</p>
      </div>
      <div>
      <h4>Country</h4>
       <p>{text.country}</p>
      </div>
    </div>
  );
}


ReactDOM.render(
    <App />,
    document.getElementById('root')
);
import java.io.*;
import java.util.*;

/*
  * To execute Java, please define "static void main" on a class
  * named Solution.
  *
  * If you need more classes, simply define them inline.
  */

class Solution {
  public static void main(String[] args) {
    ArrayList<String> strings = new ArrayList<String>();
    strings.add("Hello, World!");
    strings.add("Running Java " + Runtime.version().feature());

    for (String string : strings) {
      System.out.println(string);
    }
  }
}
Array.prototype.myMap = function(cb) {
  let res = [];
  for(let i=0; i<this.length; i++) {
    res.push(cb(this[i], i, this));
  }
  return res;
}


console.log([1,2,3,4,5].myMap((item) => item > 3)); // [false, false, false, true, true]

Featured content