Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

205
Views
Lea cada palabra individual en cadena por 'si'

¿Hay alguna manera de hacer que Java lea cada palabra individual por 'si' en la cadena? Haré mi mejor esfuerzo para explicar esto...

 public class test{ public static void main(String[] args){ String sentence = "testing1 testing2 testing3 testing4" //Scan first word \/ if(sentence.equals("testing1"){ //scan second word \/ if(sentence.equals("testing2"){ //scan third word \/ if(sentence.equals("testing3"){ System.out.println("Works good!") } } } } }

Si me puedes ayudar te lo agradecería mucho.

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Puede usar Scanner.next() como se muestra a continuación:

 String sentence = "testing1 testing2 testing3 testing4"; try (Scanner sc = new Scanner(sentence)) { if (sc.next().equals("testing1")) { if (sc.next().equals("testing2")) { if (sc.next().equals("testing3")) { if (sc.next().equals("testing4")) { System.out.println("Works good!"); } } } } }
over 4 years ago · Santiago Trujillo Report

0

Si entiendo su pregunta correctamente, puede intentar algo como esto:

 public static void main(String[] args){ String sentence = "testing1 testing2 testing3 testing4"; String[] arrayOfWords = sentence.split(" "); // split the sentence according to the spaces Scanner in = new Scanner(System.in); //Scan first word System.out.println("Insert First Word"); if(arrayOfWords[0].equals(in.next())){ System.out.println("Insert Second Word"); if(arrayOfWords[1].equals(in.next())){ System.out.println("Insert Third Word"); if(arrayOfWords[2].equals(in.next())){ System.out.println("Works good!"); } } } }

por ejemplo:

 Insert First Word testing1 Insert Second Word testing2 Insert Third Word testing3 Works good!
over 4 years ago · Santiago Trujillo Report

0

String[] array = sentence.split(" "); //Scan first word \/ if(array[0].equals("testing1"){ //scan second word \/ if(array[1].equals("testing2"){ //scan third word \/ if(array[2].equals("testing3"){ System.out.println("Works good!") } } }
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!