Well,according to the question program has to determine whether the list of integers is sorted in non-decreasing order i.e in increasing order or ascending order.
Below is the source code along with the comments to understand it better.
Source Code:-
import java.util.Scanner;//to use scanner function
public class Main //class named main
{
public static void main(String[] args) //main function
{
Scanner sc = new Scanner(System.in);
int n,count=0;
System.out.println("Enter the number of integers ");
n=sc.nextInt();
int arr[] = new int[n];
System.out.println("Enter the integers:-");
for(int i=0;i<n;i++)
{
arr[i]=sc.nextInt();//taking integers from the user
}
for(int i=0;i<n-1;i++)
{
if(arr[i]<arr[i+1])
count++; //determining whether it is sorted or not
}
if(count==n-1)
System.out.println("Yes,it is sorted in non descending order");
else
System.out.println("No,it is not sorted in non descending order");//finally printing results
}
}
Screenshot of the source code(Refer for better understanding of identation):-
Output of the code:-
Hope it helps...
Thankyou...... :-)
java code Write a method that given a list of integers as a reference to its...
Write a method max() that takes a reference to the first node in a linked list as argument and returns the value of the maximum key in the list. Assume that all keys are positive integers, and return 0 if the list is empty. In java
write the java code to convert a linked list of integers, to a stack of integers. thus your code will traverse the linked listand populate the stsck. linked list 1->2->3. becomes stack 3 First Last 2 1
Java 3) Write the-G-code to convert a linked list of integers, to a stack of integers. Thus, your code will traverse the linked list and populate the stack. [ 15 points ] Linked List 1→ 2→ 3 Stack 3 becomes First Last
You are given a Node class and a List class: Write a java method insertNodeBefore() which takes two integers (int ref which is the data of the node that we need to insert a new node before, and int d which is the data of the new node we want to insert), for the list mylist.
java code Write a method called concatenate that takes as input two references h1 and h2 to the beginning of two different lists and concatenates them in the list referenced by h1. [ Please select file(s) Select file(s)
java code Write a method called reverse that takes an array of integers as an input and returns the same values in reverse order as the output. Test your method in the main.
help please! due tomorrow! Write code in Java Write a program that takes as input an unordered list of integers, creates a Btree of minimum degree t 4 and then outputs the sorted list of integers. A simple inorder traversal of the B tree will output the list of the integers in a increasing order. You can choose your programming language and the platform you run on. The documentation is required for any programming assignment.
5. Given the following class definition, write Java code that implements the addFirst method public class MyLinkedList<E> { private Node<E> head, tail; private int size 0; // Number of elements in the list /** Add an element to the beginning of the list */ public void addFirst (E e) { private static class Node<E> { E element; Node<E> next; public Node (E element) { = element; this.element
3. Java: Write a Java method to swap two integers. Attach your code as well as a test run screenshot.
Using Java You are given a Node class and a List class: public class Node { int data; Node next; } public class List { Node first; } You are also given a Stack class. The following functions are available for use: public class Stack { public boolean isEmpty(){}; public void push(int n){}; public int pop(){};} Write a Java method snglyRevToStck that pushes the data found in a linked list t in reverse order into the stack...