write those 3 questions (class)

Ads
 

write those 3 questions (class)

1) write a function minE which takes an array of distinct integers and returns the smallest number. (If this is too easy return the 2nd smallest element.) (If this is still too easy, also pass an int k to minE and return the k smallest element.) 2) write a function rev which takes an array of integers and reverses it. 3) write a function isDistinct which takes an array of integers and returns a boolean, indicating

View Answers

October 10, 2012 at 2:55 PM

Here is an example that accepts the integers from the user and find the smallest and second smallest number from the array. It also reverses the array of numbers.

import java.util.*;

public class Smallest {
public static void minE(int numbers[]){
     int smallest = numbers[0];
     int secondSmallest = numbers[1];

     for (int i = 1; i < numbers.length; i++) {
        if (numbers[i] < smallest) {
            secondSmallest = smallest;
            smallest = numbers[i];
        }
     }
     System.out.println("Smallest value: " + smallest); 
     System.out.println("Second Smallest value: " + secondSmallest);
    }
    public static void rev(int numbers[]){
        System.out.println("Numbers in reverse order: ");
        for (int i = numbers.length-1; i >=0; i--) {
        System.out.println(numbers[i]);
      }
    }
    public static void main(String[] args) {
    Scanner kybd = new Scanner(System.in);
    int[] numbers = new int[5];

    System.out.println("Enter 5 integers: ");
    for (int i = 0; i < numbers.length; i++) {
        numbers[i] = kybd.nextInt();
    }
    minE(numbers);
    rev(numbers);
  }
}

Ads









Related Tutorials/Questions & Answers:
write those 3 questions (class)
write those 3 questions (class)  1) write a function minE which takes... an int k to minE and return the k smallest element.) 2) write a function rev which takes an array of integers and reverses it. 3) write a function isDistinct which
3 queries on java class
3 queries on java class  Hey. I need to do 3 queries on same class ( JAVA) One is to populate the combobox, the another one to populate tje jlist and the last one to use on button to open a file from database (BLOB) Can some
Advertisements
Write an applet program for displaying 3 different sentences with 3 different colors
Write an applet program for displaying 3 different sentences with 3 different colors  Write an applet program for displaying 3 different sentences with 3 different colors
Write Full concept of abstract class
Write Full concept of abstract class  Abstract class
Inner class - Java Interview Questions
Inner class  whether inner class can implement any interface(Runnable... the problem : class InnerClass1 { private int countDown = 5; private Inner inner; private class Inner extends Thread { Inner(String name
questions
calculator 2. write a program to print no of days in a given month Q. 3...questions   Q. 1 programes on if....else 1. write a program... to check whether entered no. ends with 5 or not 3. write a program to find
write a program to demonstrate wrapper class and its methods......
write a program to demonstrate wrapper class and its methods......  write a program to demonstrate wrapper class and its methods
Java Interview Questions 3
Java Interview Questions page 3   ... serialization tools that your class is serializable. Question: . How many... in order to make your class externalizable. These two methods
3
java.io package  The java.io package includes a PrintStream class that has two formatting methods that we can use to replace print () and println (). Find this two methods & Describe with your own examples   
Write a program that makes use of a class called Employee that will calculate an employee's weekly paycheque.
Write a program that makes use of a class called Employee that will calculate an employee's weekly paycheque.  Write a program that makes use of a class called Employee that will calculate an employee's weekly paycheque. Design
write a program to evaluate the following investment equation make use of wrapper class v=p(1+r)rest to n
write a program to evaluate the following investment equation make use of wrapper class v=p(1+r)rest to n  write a program to evaluate the following investment equation make use of wrapper class v=p(1+r)rest to n
Given a list of methods for a stateful or stateless session bean class, define which of the following operations can be performed from each of those methods: SessionContext interface metho
Given a list of methods for a stateful or stateless session bean class... of those methods: SessionContext interface methods, UserTransaction... session bean class, define which of the following operations can
Software Questions and Answers
Software Questions and Answers View Software Questions and Answers online Discuss Software development questions, ask your questions and get answers online. Here you can find questions asked by developers in the past. You can
Software Questions and Answers
Software Questions and Answers       View Software Questions and Answers online Discuss Software development questions, ask your questions and get answers online. Here you can
Spring 3
Spring 3  Hi I want to know how to write code Spring 3 for registration and login pages with help of data bse.Please help me I am new to Spring
java questions
java questions  can i write an inner class in an interface
Core Java Interview Questions!
Core Java Interview Questions   ... as transient in a Serializable class and the class is written... the class is retrieved from the ObjectStream the value of the variable becomes
class
class  can any body give me idea how to write code for Country.java is a class to represent a country in medal tally. It has an attribute of country... medals. In this class, you should also define constructors, and assessor, mutator
programming questions
programming questions  this is my assignment questions please help me... Write programs with corresponding output screens to demonstrate the above concepts. Write a program in C# language to perform the following operations: a. Basic
Java write file
. In the example subclasses of  Writer abstract class are used to write... class.           Write_File... Java write file      
multiple choice questions program
multiple choice questions program  how can i implement the program to store 10 multiple choice questions in one class to develop a oneline quiz with using java language
multiple choice questions program
multiple choice questions program  how can i implement the program to store 10 multiple choice questions in one class to develop a oneline quiz with using java language
Class
Area of rectangle : 6 Value of x in another class : 3 Area... Class, Object and Methods       Class : Whatever we can see in this world all the things
Corejava Interview,Corejava questions,Corejava Interview Questions,Corejava
;    Q 1 : How should I create an immutable class ? Ans...;     Q 3 : What is dynamic method dispatch ?  Ans... different behavior is required, you only require to write a class implementing
servlet questions
servlet questions  pls send servlet interview questions to [email protected]
multiple choice questions
multiple choice questions  how can i store 10 multiple choice questions in one class with using java language
multiple choice questions
multiple choice questions  how can i implement the program to store multiple questions in class with using core java concepts
How to write a file in Java?
How to write a file in Java? To write a file in Java use the class FileWriter and BufferedWriter. Class FileWriter: The FileWriter class is used to write... or False. BufferedWriter: The BufferWriter class is used to write data from
Java write to stream
Java write to stream       Following example demonstrates, how to write data in to the stream. In the example subclass CharArrayWriter of  abstract Writer class is used
@Controller Annotation Example in Spring 3
@Controller Annotation Example in Spring 3: In this section we will see how we can create annoted controller class in Spring 3. You can @Controller annotation in the Java class to make it controller. In this tutorial we are creating
WRITE AND TEST
WRITE AND TEST   WRITE AND TEST PROGRAM TO ACCEPT A STRING? 1).WHICH STARTS WITH 'S' OR 's' 2).ENDS WITH "nd" 3) THE LENGTH OF THE STRING SHOULD BE 10 OR LESS

Ads