0votos

Hola Ramon en Java

por LDBUAI usando Ubuntu, Eclipse hace 1 año

In this solution there are three variables that were created to use the "while" sentence and validate on it the value of the index belonging to the array of Strings.

Combinaciones

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package com.java2017.exercise2; 
import java.util.Random; 
 
public class RandomWords { 
 
     
    public static void main(String[] args) { 
        // TODO Auto-generated method stub 
        String wordsArray[] = {"Hola", "Señor", "Ramón"}; 
        Random index = new Random(); 
        int flag = index.nextInt(3); 
        String text = wordsArray[flag]; 
        int nFlag = index.nextInt(3); 
        while(nFlag == flag){ 
                nFlag = index.nextInt(3); 
        text += " " + wordsArray[nFlag]; 
        int mFlag = index.nextInt(3); 
        while(mFlag == flag || mFlag == nFlag){ 
                mFlag = index.nextInt(3); 
        text += " " + wordsArray[mFlag]; 
        System.out.println(text); 
 

Comenta la solución

Tienes que identificarte para poder publicar tu comentario.