Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Modify the program to print 1st, 2nd, 3rd, 4th and 5th rather than 1th, 2th, etc., without introducing redundant statements (Hint: Precede the if-else statement

Modify the program to print "1st", "2nd", "3rd", "4th" and "5th" rather than "1th", "2th", etc., without introducing redundant statements (Hint: Precede the "if-else" statement with a separate if-else statement that determines the appropriate ending based on the number).

import java.util.ArrayList; import java.util.Scanner;

public class MostPopularOS { public static void main (String [] args) { Scanner scnr = new Scanner(System.in); ArrayList operatingSystems = new ArrayList(); int nthOS = 1; // User input, Nth most popular OS

// Source: Wikipedia.org, 2013 operatingSystems.add(new String("Windows 7")); operatingSystems.add(new String("Windows XP")); operatingSystems.add(new String("OS X")); operatingSystems.add(new String("Windows Vista")); operatingSystems.add(new String("Windows 8")); operatingSystems.add(new String("Linux")); operatingSystems.add(new String("Other"));

System.out.print("Enter N (1-7): "); nthOS = scnr.nextInt();

if ((nthOS >= 1) && (nthOS <= 7)) { System.out.print("The " + nthOS + "th most popular OS is "); System.out.println(operatingSystems.get(nthOS - 1)); }

return; } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Autonomous Database In Enterprise Architecture

Authors: Bal Mukund Sharma, Krishnakumar KM, Rashmi Panda

1st Edition

1801072248, 978-1801072243

More Books

Students also viewed these Databases questions

Question

How do you think you would use break-even analysis? LO.1

Answered: 1 week ago

Question

How wide are Salary Structure Ranges?

Answered: 1 week ago