write those 3 questions (class)

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);
  }
}









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
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
Pattern class - Java Interview Questions
Pattern class  1)Write a program to find out numeric occurences in an input file by using pattern class
java bits 3 - Java Interview Questions
java bits 3  Given: 11. public class Test { 12. public static void.... System.out.print(?2 ?); 20. if ((b2 = true) && b1) 21. System.out.print(?3 ?); 22. } 23. } What is the result? A. 2 B. 3 C. 1 2 D. 2 3 E. 1 2 3 F. Compilation
OBJECT CLASS - Java Interview Questions
for a particular class you need to write code in the constructor in such a way that it keeps the track of the new instances of the class.Here is the example. class A{ A(){ static int a; a++; } class B{ public static void main(String args
inner class - Java Interview Questions
Java Inner Class  How many classes we can create in an inner class?  How many classes we can create in an inner class ANS :- Within Main class{} we can create any number of the inner classes according
java class - Java Interview Questions
java class  What is the speciality of class? what is the use... having same name,same parameters and same return types of a super class in its subclass. For ex- class A { int i; A(int a, int b) { i = a+b; } void add
abstract class - Java Interview Questions
abstract class  Explain the abstract class and abstract method()?  Hi Friend, Please visit the following links: http://www.roseindia.net/java/master-java/abstract-class.shtml http://www.roseindia.net/help/java
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
Use of write method of CheckedOutputStream class in java.
Use of write method of CheckedOutputStream class in java. In this tutorial, we will discuss the use of write(int b) method of CheckedOutputStream class... to use write(int b) method of CheckedOutputStream class. The FileInputStream class
abstract class - Java Server Faces Questions
abstract class  Hello sir, I have problem with seeing entity class within abstract class. this is the entity class that i want to get: public class Product extends AbsEntity implements Serializable
abstract class - Java Server Faces Questions
abstract class  Hello sir, I have problem with seeing entity class within abstract class. this is the entity class that i want to get: public class Product extends AbsEntity implements Serializable
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 CODE IN STRUTS ACTION CLASS FOR CHECK BOXES AND RADIO BUTTONS - Struts
WRITE A CODE IN STRUTS ACTION CLASS FOR CHECK BOXES AND RADIO BUTTONS  Hello frnds, I am sending this second time help me out. i need help from u esteemed and talented people.iwould like to write code in struts action class
Java Interview Questions 3
Java Interview Questions page 3   ... serialization tools that your class is serializable. ADS_TO_REPLACE_1 Question... methods in order to make your class externalizable. These two methods
questions
. write a program to print no of days in a given month Q. 3 programes on while...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 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
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
where singleton class used in java - Java Interview Questions
where singleton class used in java  where singleton classes are used in j2ee web application.can we use it for connection pooling. Thanks Prakash
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
creating new file with File class - JSP-Interview Questions
of FileOutputStream class. If we give the path as from the file uploading location will it work
Module in Flex 3
Module in Flex 3:- In the Flex 3,  Modules are dynamically loadable SWF that contains an IFlexModuleFactory class factory. They can be loaded... with the help of module class. More then one applications also used these modules
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
Java write file
Java write file       Following example demonstrates, how to create and write a file. In the example subclasses of  Writer abstract class are used to write
class
class  Is a class a subclass of itself
Difference between extends thread class vs implements runnable interface - Java Interview Questions
Difference between extends thread class vs implements runnable interface  Hi Friends, can you give difference between extending thread class... want to extend the Thread class then it will make your class unable to extend
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
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..._TO_REPLACE_5 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
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
can i restrict a class that it will not allows create more than two objects - Java Interview Questions
can i restrict a class that it will not allows create more than two objects  hi all, can i restrict a class that it will not allows create more than two objects can any help me please. Thaks bala k
How to call business deleget class(EJB) from JSF Page? - Java Server Faces Questions
How to call business deleget class(EJB) from JSF Page?  Hi, How to call a biz i.e. business deleget class(EJB) from JSF Page? I am creating one 3-tier banking application. I am using JSF 1.2 I want to know that.How to call
Java Write To InputStream
Java Write To InputStream In this tutorial you will learn how to write to InputStream in java. Write to file from InputStream in java you may use the InputStream class of java.io package. This class reads the streams of bytes
Design a class named BankAccount to hold datas for a bank account in Java using Bluej Software - Java Interview Questions
Design a class named BankAccount to hold datas for a bank account in Java using Bluej Software  1)Design a class named BankAccount to hold... service charges The class should have the following methods: Constructor
Software Questions and Answers
as compared to Flex 3. Ask Flex questions  and browser questions and answers...Software Questions and Answers View Software Questions and Answers online Discuss Software development questions, ask your questions and get answers
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
@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
clone() method of object class - Java Interview Questions
How to store two integer value in a separate file and retrieve those values
How to store two integer value in a separate file and retrieve those values  I need to save two values so i can use those values later i came up with idea of saving those values in a separate file and updating values in file
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
java questions
java questions  can i write an inner class in an interface
3 Java Programs for Beginners
3 Java Programs for Beginners  Write a program that prompts the user... (inclusive) and their squares and the sum of their squares. Write a program that reads a string from a user and then prints it out one character at a time. Write
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
J2ME RMS Read Write
J2ME RMS Read Write       This Application specially tries to explain how to read and write the data using RecordStore class. In the RecordStore class the following methods
Given a list of responsibilities related to session beans, identify those which are the responsibility of the session bean provider and those which are the responsibility of the EJB contai
Given a list of responsibilities related to session beans, identify those which are the responsibility of the session bean provider and those...;Chapter 3. Session Bean Component Contract Next    
write spreadsheet
write spreadsheet  what is the java code to write a spreadsheet to database
write spreadsheet
write spreadsheet  what is the java code to write a spreadsheet to database

Ads