Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

import java.util.Scanner; public class TableOrder { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System .

import java.util.Scanner;
public class TableOrder
{
public static void main
(
String
[
]
args
)
{
Scanner scanner
=
new Scanner
(
System
.
in
)
;
/
/
Read the number of parties
int n
=
scanner
.
nextInt
(
)
;
/
/
Initialize an array to store the count of each table size
int
[
]
tables
=
new int
[
4
]
;
/
/
Sizes:
2
,
4
,
6
,
8
/
/
Process each party size and update the table count
for
(
int i
=
0
; i
<
n; i
+
+
)
{
int group
=
scanner
.
nextInt
(
)
;
int idx
=
(
group
-
1
)
/
2
;
tables
[
idx
]
+
+
;
}
/
/
Output the result in ascending order of popularity
for
(
int i
=
0
; i
<
4
; i
+
+
)
{
int size
=
2
*
(
i
+
1
)
;
System.out.println
(
size
+
"
:
"
+
tables
[
i
]
)
;
}
}
}
change this program with less popularity to most popularity with different input every time if i enter
4
4
4
4
6
6
8
2
,
so in that case
4
should come at top,then
6
,
then
8
then
2
in output, write java program without using hash map

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

Step: 3

blur-text-image

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

The Accidental Data Scientist

Authors: Amy Affelt

1st Edition

1573877077, 9781573877077

More Books

Students also viewed these Databases questions

Question

Define organization development (OD)

Answered: 1 week ago