write those 3 questions (class)

Ads

 
 

Share on Google+Share on Google+

mayzhu
write those 3 questions (class)
1 Answer(s)      4 years and 7 months ago
Posted in : Java Beginners

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

Ads
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
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
Write Full concept of abstract class
Write Full concept of abstract class  Abstract class
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 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 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
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
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
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
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
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
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
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
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
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
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
@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
help me 3
help me 3  write aprogram in java using two dimentional array.Accept the two dimentional array from the user and perform addition and subtraction of these two arrays and display the result for each add and subtruct
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
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
JSP Tutorials - Page 3
JSP Tutorials - Page 3
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 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    
Tutorials   
Java Spring Hibernate Struts Training What type of programming language is Java? How do beginners learn about Java? ClassNotFoundException HttpRequestInterceptor java.lang.noclassdeffounderror: org/apache/http/httprequest noclassdeffounderror: org/apache/http/client/methods/httpurirequest java.lang.NoClassDefFoundError: org/apache/http/client/HttpClient How do I resolve this Java Class not found exception? httpclient java.lang.NoClassDefFoundError Apache Commons ioutils maven dependency Read/Convert an inputStream to a String What is the meaning of Java Platform? Why Java is a platform independent language? What is the benefits of learning Core Java? Which technology should I learn after Java? What is array in java with example? How to Convert ArrayList to Array? How to substring in Java? How to format number in Java? What is instance variable in Java? How to download MySQL JDBC driver? What is Calendar class in Java? Which is the best Java tutorials for beginners? How to rename a file in Java? How to delete file in Java code? How to get day from date in Java using Calendar? How to get day of week in Java? How to calculate Date Difference in Java? How to compare date in Java? How to declare array in Java? How to calculate average of array in Java? What is Array in Java? write a java program to find the summation of all the integers entered on command line Sum of two numbers using command line arguments in Java How to create and use Array in Java? How to pass command line arguments in Java? How to create Applet Hello World? Appending String efficiently in Java How to append String in Java? How to list even numbers between 1 and 100? How to add BigDecimal in Java? What is Abstraction In Java? Which is best Beginners Java Tutorial? What is java.util package? Create list from array in Java Filter collection in Java 8 What is the best way to filter a Java Collection? Easy way to transform Collection to Array? How to convert Collection to Array in Java? What are Basic Java Language Elements? Advanced Java Tutorials in 2017

Ads

 
Advertisement null

Ads