I have a textarea
with an attribute placeholder="tu comentario"
. I would like to change the color of said text but I don't know how to reference it in the style sheet.
Sergio AG's questions
I'm working with cursors whose behavior parameter is SCROLL
but I don't understand what the purpose of two of its functions is when doing the FETCH
.
I don't understand what they do or what they are used for FETCH ABSOLUTE and FETCH RELATIVE.
My question is if in the declaration of the cursor we do not specify any parameter of its behavior, such as SCROLL
or LOCAL
or READ_ONLY
, what value will it take by default?
That is, if I write this
DECLARE nombreCursor CURSOR FOR sentencia
What parameter will it take by default?
What is the difference in semaphores between using a
.acquire()
and a .tryAcquire()
?
Semaphore sem = new Semaphore(1);
sem.acquire();
sem.tryAcquire();
I have this little code. It happens that when the time comes to enter the third data (the name), it skips it, it is as if it automatically hit enter and could not write anything:
Scanner sc = new Scanner(System.in);
System.out.println("Introduce el primer numero: ");
int num1 = sc.nextInt();
System.out.println("Introduce el segundo numero: ");
int num2 = sc.nextInt();
System.out.println("Introduce tu nombre: ");
String nombre = sc.nextLine();
System.out.println("--------------"); //esto no es mas que decoracion
In such a way that the console output would be something like this:
Introduce el primer numero:
1
Introduce el segundo numero:
2
Introduce tu nombre:
-------------
I don't know why this happens. It's like the Scanner class goes crazy when I first ask it for int and then for String. Do you know what happens?
I have the following code that allows me to read the content of a file (in this case txt) by console in Java. I don't quite understand what the function of FileInputStream, InputStreamReader and BufferedReader is. What exactly do they do? Thank you!
public class LeerFichero {
public static void main(String[] args) {
int numero = 0;
try {
Scanner sc = new Scanner(System.in);
System.out.println("Introduce el nombre del fichero: ");
String nombreFichero = sc.nextLine();
String salida = "C:\\Users\\SAG\\Desktop\\Repaso\\src\\leerarchivo\\";
FileInputStream fichero = new FileInputStream(salida + nombreFichero + ".txt");
InputStreamReader osw = new InputStreamReader(fichero);
BufferedReader br = new BufferedReader(osw);
while(br.ready()) {
String linea = br.readLine();
System.out.println(linea);
}
}catch(FileNotFoundException e) {
e.getMessage();
}catch(IOException e) {
e.getMessage();
}
}
}
My question is whether it is strictly mandatory to close a BufferedReader
with .close()
.
I'm practicing with reading and writing files and, for example, if BufferedWriter
you don't close it with .close()
it doesn't do anything, therefore it is mandatory to close it.
Does the same thing happen with BufferedReader
, that is, is it strictly mandatory to close it? Or can it be left unlocked? Is there any drawback?
I'm making a game in Android Studio and at a certain point I go to another screen. How can I say "lock" that new screen to avoid going back? Thank you!
I have a little question on Android. Suppose I have an EditText, in which the user will enter a number by keyboard. How can I collect this value? Let's see, I know how to do it as if it were a text string, which would then be where I do this:
private EditText et1;
et1 = (EditText)findviewbyid(R.id.et1);
String texto = et1.getText().toString();
But I won't do it if instead of text it was a number, for example a number referring to age. How would this value be collected? Thanks and greetings!
How can I make a button that sends me to another page that I specify? So far I've only been able to do it with the tag <a>
and its href and target attributes. But I can't do it with a <button>
.
I have here an exercise called Parking. I understand slightly, but there is one thing that is not clear to me, and I mean the parameter that takes Semaphore sem = new Semaphore(este_parametro_me_refiero)
. I appreciate the help! She left you the code:
package ejercicio6_Parking;
import java.util.concurrent.Semaphore;
public class Coche implements Runnable{
private Semaphore sem;
private int numeroCoche;
public Coche(int numeroCoche, Semaphore sem) {
this.numeroCoche = numeroCoche;
this.sem = sem;
}
@Override
public void run() {
System.out.println("Arranca el coche " + numeroCoche);
while(true) {
//el coche va por la ciudad entre 1 y 30s e intenta entrar al parking
try {
Thread.sleep( (long) (Math.random()*30000) );
System.out.println("El coche " + numeroCoche + " llega al parking e intenta entrar.");
sem.acquire();
System.out.println("El coche " + numeroCoche + " entra.");
Thread.sleep( (long) (Math.random()*30000));
System.out.println("El coche " + numeroCoche + " sale.");
System.out.println(sem.availablePermits() + " plazas libres.");
System.out.println(sem.getQueueLength() + " coches en la cola.");
sem.release();
}catch(InterruptedException e) {
e.printStackTrace();
}
}
}
}
package ejercicio6_Parking;
import java.util.concurrent.Semaphore;
public class Principal {
public static void main(String[] args) {
Semaphore sem = new Semaphore(0);
for(int i=0; i<40; i++) {
Coche c = new Coche(i+1, sem);
Thread th = new Thread(c);
th.start();
}
}
}
I would like to know how to load the data from a sql query in a list view. No matter how hard I try I can't do it :S
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("create table usuarios(nombre text primary key, edad int, puntuacion int)");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("drop table usuarios");
db.execSQL("create table usuarios(nombre text primary key, edad int, puntuacion int)");
}
public class Ranking extends AppCompatActivity{
private ListView lv1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ranking);
lv1 = (ListView)findViewById(R.id.lv1);
ArrayList <String> ranking = new ArrayList<>();
AdminSQLiteOpenHelper juego = new AdminSQLiteOpenHelper(this, "juego", null, 5);
SQLiteDatabase bd = juego.getWritableDatabase();
Cursor fila = bd.rawQuery("select nombre, puntuacion from usuarios", null);
if(fila.moveToFirst()){
fila = bd.rawQuery("select nombre, puntuacion from usuarios", null);
ranking.add(fila.getString(0) + " - " + fila.getString(1));
while(fila.moveToNext()){
ranking.add(fila.getString(0) + " - " + fila.getString(1));
}
}
bd.close();
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, ranking);
lv1.setAdapter(adapter);
}
}