Jump to content

Sentinel Controlled

- - - - -

  • Please log in to reply
1 reply to this topic

#1
juniorjava

juniorjava

    Newbie

  • Members
  • Pip
  • 1 posts
anyone can help me modified the code below ? i don know how to apply Sentinel..please :crying:

import javax.swing.JOptionPane;

import java.util.*;


public class main {


public static void main(String[] args) {


int total = 0 ;

String[] name = new String[10];

String name1;

String[] age = new String[10];

String age1;

String[] hei = new String[10];

String hei1;


for(total=0 ;total < 10;total++){


Scanner input = new Scanner(System.in);


name1 = JOptionPane.showInputDialog("Please enter student's name: ");

name[total] = name1;


age1 = JOptionPane.showInputDialog("Please enter student's age: ");

age[total] = age1;


hei1 = JOptionPane.showInputDialog("Please enter student's height: ");

hei[total] = hei1;


}

JOptionPane.showMessageDialog(null,"You entered: \n" +"Name: "+ name[0] +", Age: "+age[0]+", Height: "+hei[0]+

"\nName: "+ name[1] +", Age: "+age[1]+", Height: "+hei[1]+

"\nName: "+ name[2] +", Age: "+age[2]+", Height: "+hei[2]+

"\nName: "+ name[3] +", Age: "+age[3]+", Height: "+hei[3]+

"\nName: "+ name[4] +", Age: "+age[4]+", Height: "+hei[4]+

"\nName: "+ name[5] +", Age: "+age[5]+", Height: "+hei[5]+

"\nName: "+ name[6] +", Age: "+age[6]+", Height: "+hei[6]+

"\nName: "+ name[7] +", Age: "+age[7]+", Height: "+hei[7]+

"\nName: "+ name[8] +", Age: "+age[8]+", Height: "+hei[8]+

"\nName: "+ name[9] +", Age: "+age[9]+", Height: "+hei[9]);

}

}

Edited by Roger, 12 February 2012 - 08:17 AM.
added code tags


#2
lethalwire

lethalwire

    while(false){ ... }

  • Members
  • PipPipPipPipPipPipPip
  • 748 posts
  • Programming Language:Java, PHP
  • Learning:Java, PHP
Ask another question like: "would you like to continue? (Type yes or no)"
Store the answer.

Then, use a while loop to determine whether you should keep going or stop.


while( the stored answer is yes ) {

   ...do stuff

   ask the user if they would like to continue

   store the answer

}






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users