Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Code that writes four radio buttons, would want them centre aligned on .html

public class ScanForWordsC {
    private static final Scanner INPUT = new Scanner(System.in);
    private static final String FILENAME = "F:/Android.html";

    public static void main(String[] args) throws FileNotFoundException {
        try (PrintStream output = new PrintStream(FILENAME)) {
            readFromUser(output);
        }
    }

    public static void readFromUser(PrintStream output) {
        String wordA = readLine("Word (a)");
        String wordB = readLine("Word (b)");
        String wordC = readLine("Word (c)");
        String wordD = readLine("Word (d)");
        String answer = readLine("Correct letter");

        output.println(radio("a", wordA, answer));
        output.println(radio("b", wordB, answer));
        output.println(radio("c", wordC, answer));
        output.println(radio("d", wordD, answer));
    }

    private static String readLine(String prompt) {
        System.out.print(prompt + ": ");
        return INPUT.nextLine();
    }

    private static String radio(String letter, String word, String answer) {
        String option = "(" + letter + ") " + word;
        String is = letter.equals(answer) ? "is" : "is not";

        return "<input type='radio' name='rbnNumber' value='You selected " 
                + option + " which " + is +  " the correct answer' />"
                + option + "<br/>";
    }
}


What I have tried:

java classes, collections and java docs
Posted
Updated 24-May-18 7:15am
Comments
Richard MacCutchan 24-May-18 7:40am    
You need to add the HTML or CSS that aligns items in the centre.

You could use CSS to set the text alignment on the parent:
text-align:center


For example:
<!DOCTYPE html>
<html>
<body style="text-align:center">
    <input type='radio'>First</input><br/>
    <input type='radio'>Second</input><br/>
    <input type='radio'>Third</input><br/>
</body>
</html>
 
Share this answer
 
code here aligns two radio buttons !but others, is there way for four buttons alignment, css would increase more code if could do with table alignment is good

private static String radio(String letter, String word, String answer)
   {

       String option = "(" + letter + ") " + word;
       String is = letter.equals(answer) ? "is" : "is not";

       return "<html><table align = 'center'><tr><td>"
               + "<input type='radio' name='rbnNumber' value='You selected"
               + option + "which" + is + "the correct answer'/>"
               + option + "<br/>"
               + "</td></tr></html>";
   }
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900