Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Fix the Java program:
Make sure the program have the "Main" function.
Code:
class RemoveDuplicates
{
publicstaticvoid Main(String[] args)
{
int a[]={1,3,5,2,3,5,3,3,5,7,9,3};
System.out.print("Before Sorting:");
for (int i=0;i<a.length; i++ )
{
System.out.print(a[i]+"\t");
}
System.out.print ("\nAfter Sorting:");
//sorting the elements
for(int i=0;i<a.length;i++)
{
for(int j=i;j<a.length;j++)
{
if(a[i]>a[j])
{
int temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
//After sorting
for(int i=0;i<a.length;i++)
{
System.out.print(a[i]+"\t");
}
System.out.print("\nAfter removing duplicates:");
System.out.print("\n Here are the distinct numbers:");
int b=0;
a[b]=a[0];
for(int i=0;i<a.length;i++)
{
if (a[b]!=a[i])
{
b++;
a[b]=a[i];
}
}
for (int i=0;i<=b;i++ )
{
System.out.print(a[i]+"\t");
}
}
}
Output:
class RemoveDuplicates
{
publicstaticvoid Main(String[] args)
{
int a[]={1,3,5,2,3,5,3,3,5,7,9,3};
System.out.print("Before Sorting:");
for (int i=0;i<a.length; i++ )
{
System.out.print(a[i]+"\t");
}
System.out.print ("\nAfter Sorting:");
//sorting the elements
for(int i=0;i<a.length;i++)
{
for(int j=i;j<a.length;j++)
{
if(a[i]>a[j])
{
int temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
//After sorting
for(int i=0;i<a.length;i++)
{
System.out.print(a[i]+"\t");
}
System.out.print("\nAfter removing duplicates:");
System.out.print("\n Here are the distinct numbers:");
int b=0;
a[b]=a[0];
for(int i=0;i<a.length;i++)
{
if (a[b]!=a[i])
{
b++;
a[b]=a[i];
}
}
for (int i=0;i<=b;i++ )
{
System.out.print(a[i]+"\t");
}
}
}
Output:
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by stepSolved in 2 steps with 1 images
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- 1 public static int sum(int x, int y){ 2 int z = x +y; 3 return z; 4 } 5 public static void main(String[] args){ 6 … 7 sum(a+2, b); 8 … 9 } write the signature of the method sum: sum(int,int) *Method name/parameter list list local variables of sum: x, y, and y are local variables of the function. list the parameters of sum: int x, int y write the line number where a call to sum occurs 7 list the arguments for the above call list the return type of sum here ______________arrow_forward1. Divisors: In a class Divisors.java, read in a maximum integer n and use nested loops to print a list of divisors for each of 1 through n as shown in the following transcript. Sample transcript (input underlined): Largest integer? 100 1: 1 2: 1 2 3: 1 3 4: 1 2 4 95: 1 5 19 95 96: 1 2 3 4 6 8 12 16 24 32 48 96 97: 1 97 98: 1 2 7 14 49 98 99: 1 3 9 11 33 99 100: 1 2 4 5 10 20 25 50 100arrow_forwardQuestion #4: Re-write the program of Question #3 using data files. The input data numbers.txt contains (positive) integer numbers. Each time the program reads a number, check whether it is a prime and stores the result in the output file Results.txt. 373 373 is Prime!! 11 11 is Prime!! 2552 is NOT prime!! 5 is Prime!! 3561 is NOT prime!! 2552 3561 numbers.txt Results.txtarrow_forward
- How do I code: public static int sum(int[] arr) public static int sum(int[] arr, int firstIndex, int lastIndex) public static double average(int[] arr) in java?arrow_forwardJava (Generic Method) - What Order?arrow_forward1. When you run the following code, what would happen?public class Question1 {public static void main(String arg[]){int i;int [] A = new int[10];int count = 0;int temp = 10;for (i=0; i < A.length; i++)if (A[i] < temp) count++;System.out.println(count);}}(a) It finds the smallest value and stores it in temp.(b) It finds the largest value and stores it in temp.(c) It counts the number of elements equal to the smallest value in list.(d) It counts the number of elements in list that are less than temp.arrow_forward
- What does the following code print out? public class MysteryNumbers static void Main(string[] args) { String one = "two"; String two String three = "1"; int number = 20; = "three"; Sentence (one, two, 3); Sentence (two, three, 14); Sentence (three, "three", number + 1); Sentence (three, two, 1); Sentence ("eight", three, number / 2); } public static void Sentence (String three, String one, int number) System.out.println (three + times + one + = " + (number * 2)); }arrow_forwardWhat does the following code do? In [1]: def mystery (a, b) : if b == 1: return a else: return a + mystery (a, b - 1) In [2]: mystery (2, 10) Out [2]: ?????arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education