You can get more than 50 points.
Please do this java program.
It's urgent.
Answers
Hi mate,
Answer: Java is a programming language that developers use to create applications on your computer. Chances are you've downloaded a program that required the Java runtime, and so you probably have it installed it on your system. Java also has a web plug-in that allows you to run these apps in your browser.
The basic steps to create the Hello World program are: write the program in Java, compile the source code, and run the program.
Write the Java Source Code. ...
Save the File. ...
Open a Terminal Window. ...
The Java Compiler. ...
Change the Directory. ...
Compile Your Program. ...
Run the Program.
The Java collections framework provides various algorithms that can be used to manipulate elements stored in data structures.
Algorithms in Java are static methods that can be used to perform various operations on collections.
Since algorithms can be used on various collections, these are also known as generic algorithms.
Let's see the implementation of different methods available in the collections framework.
1. Sorting Using sort()
The sort() method provided by the collections framework is used to sort elements. For example,
Search Programiz
Java Algorithms
Java Algorithms
In this tutorial, we will learn about different algorithms provided by the Java collections framework with the help of examples.
The Java collections framework provides various algorithms that can be used to manipulate elements stored in data structures.
Algorithms in Java are static methods that can be used to perform various operations on collections.
Since algorithms can be used on various collections, these are also known as generic algorithms.
Let's see the implementation of different methods available in the collections framework.
1. Sorting Using sort()
The sort() method provided by the collections framework is used to sort elements. For example,
import java.util.ArrayList;
import java.util.Collections;
class Main {
public static void main(String[] args) {
// Creating an array list
ArrayList<Integer> numbers = new ArrayList<>();
// Add elements
numbers.add(4);
numbers.add(2);
numbers.add(3);
System.out.println("Unsorted ArrayList: " + numbers);
// Using the sort() method
Collections.sort(numbers);
System.out.println("Sorted ArrayList: " + numbers);
}
}
Output
Unsorted ArrayList: [4, 2, 3]
Sorted ArrayList: [2, 3, 4]
Here the sorting occurs in natural order (ascending order). However, we can customize the sorting order of the sort() method using the Comparator interface.
2. Shuffling Using shuffle()
The shuffle() method of the Java collections framework is used to destroy any kind of order present in the data structure. It does just the opposite of the sorting. For example,
import java.util.ArrayList;
import java.util.Collections;
class Main {
public static void main(String[] args) {
// Creating an array list
ArrayList<Integer> numbers = new ArrayList<>();
// Add elements
numbers.add(1);
numbers.add(2);
numbers.add(3);
System.out.println("Sorted ArrayList: " + numbers);
// Using the shuffle() method
Collections.shuffle(numbers);
System.out.println("ArrayList using shuffle: " + numbers);
}
}
Output
Sorted ArrayList: [1, 2, 3]
ArrayList using shuffle: [2, 1, 3]
When we run the program, the shuffle() method will return a random output.
i hope it helps you..
Input :
- import java.util.Scanner;
- public class Student_Marks
- {
- public static void main(String[] args)
- {
- int n, total = 0, percentage;
- Scanner s = new Scanner(System.in);
- System.out.print("Enter no. of subject:");
- n = s.nextInt();
- int marks[] = new int[n];
- System.out.println("Enter marks out of 100:");
- for(int i = 0; i < n; i++)
- {
- marks[i] = s.nextInt();
- total = total + marks[i];
- }
- percentage = total / n;
- System.out.println("Sum:"+total);
- System.out.println("Percentage:"+percentage);
- }
- }
Output:
$ javac Student_Marks.java
$ java Student_Marks
Enter no. of subject:5
Enter marks out of 100:
86
89
91
82
78
Sum:426
Percentage:85
❤️