Mostrando entradas con la etiqueta Hackerrank. Mostrar todas las entradas
Mostrando entradas con la etiqueta Hackerrank. Mostrar todas las entradas

jueves, 27 de abril de 2017

Revising the Select Query I

Revising the Select Query 









Query all columns for all American cities in CITY with populations larger than 100000. The CountryCode for America is USA.
Input Format
The CITY table is described as follows:
select * from CITY where CITY.POPULATION >'100000' and COUNTRYCODE='USA';


****************************************
Query the names of all American cities in CITY with populations larger than 120000. The CountryCode for America is USA.

Input Format
The CITY table is described as follows:CITY.jpg
select CITY.NAME from CITY where CITY.POPULATION >'120000' and COUNTRYCODE='USA';


*********************************************
Query all columns (attributes) for every row in the CITY table.

Input Format
The CITY table is described as follows:CITY.jpg

SELECT * FROM CITY

********************************************************
Query all columns for a city in CITY with the ID 1661.

Input Format
The CITY table is described as follows:
SELECT * FROM CITY WHERE CITY.ID = '1661';

************************************************************************************


Query all attributes of every Japanese city in the CITY table. The COUNTRYCODE for Japan is JPN.

Input Format
The CITY table is described as follows:

SELECT * FROM CITY WHERE CITY.COUNTRYCODE='JPN';

***********************************************************************
Query the names of all the Japanese cities in the CITY table. The COUNTRYCODE for Japan is JPN.
Input Format
The CITY table is described as follows:
SELECT city.name FROM CITY WHERE CITY.COUNTRYCODE='JPN';

************************************************


Query a list of CITY and STATE from the STATION table.

Input Format
The STATION table is described as follows:
where LAT_N is the northern latitude and LONG_W is the western longitude.

SOLUTION:

           SELECT CITY,STATE from STATION;


Explanation:

    The question is that we have been asked to write a query that lists the CITY and STATION fields present in the table STATION.

viernes, 24 de marzo de 2017

Hackerank

Most HackerRank challenges require you to read input from stdin (standard input) and write output to stdout (standard output).
One popular way to read input from stdin is by using the Scanner class and specifying the Input Stream as System.in. For example:
Scanner scanner = new Scanner(System.in);
String myString = scanner.next();
int myInt = scanner.nextInt();
scanner.close();

System.out.println("myString is: " + myString);
System.out.println("myInt is: " + myInt);
The code above creates a Scanner object named  and uses it to read a String and an int. It then closes the Scanner object because there is no more input to read, and prints to stdout using System.out.println(String). So, if our input is:
Hi 5
Our code will print:
myString is: Hi
myInt is: 5

import java.util.*;

public class Solution {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();
        int c = scan.nextInt();
        scan.close();
        // Complete this line
        // Complete this line

        System.out.println(a);
        System.out.println( b);
        System.out.println( c);
        // Complete this line
        // Complete this line
    }
}

*******************************************************
import java.util.Scanner;

public class Solution {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int i = scan.nextInt();
double d = scan.nextDouble();
       scan.nextLine();
          String s=scan.nextLine();
        // Write your code here.

        System.out.println("String: " + s);
        System.out.println("Double: " + d);
        System.out.println("Int: " + i);
    }
}



Triki part nextLine() toma los expacios tambien, cosa que next no lo hace

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package hackerrank1;

import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Hackerrank1 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
            int i = 4;
        double d = 4.0;
        String s = "HackerRank ";

        Scanner scan = new Scanner(System.in);
        int j=0;

String e="hello";

int myInt = scan.nextInt();
int myInt2 = scan.nextInt();
scan.nextLine();
String myString = scan.nextLine();

scan.close();


double e1= myInt2*1.0;

System.out.println(i+ myInt);
System.out.println(d+ e1);
System.out.println("myString is: " + myString);




    }

**************************

otro ejemplo
import java.util.Scanner;

public class CadenaDeCaracteres2 {
    public static void main(String[] ar) {
        Scanner teclado=new Scanner(System.in);
        String apenom1,apenom2;
        int edad1,edad2;
        System.out.print("Ingrese el apellido y el nombre:");
        apenom1=teclado.nextLine();
        System.out.print("Ingrese edad:");
        edad1=teclado.nextInt();
        System.out.print("Ingrese el apellido y el nombre:");
        teclado.nextLine();
        apenom2=teclado.nextLine();
        System.out.print("Ingrese edad:");
        edad2=teclado.nextInt();
        System.out.print("La persona de mayor edad es:");
        if (edad1>edad2) {
            System.out.print(apenom1);
        } else {
            System.out.print(apenom2);
        }
    }
}

zen consultora

Blogger Widgets