Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners write those 3 questions (class)

Have Programming Question? Ask it here!
 
 
 


mayzhu
write those 3 questions (class)
1 Answer(s)      a year and 6 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


Advertisement
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
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
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
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
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
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
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
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
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 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
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
@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
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
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
Dynamic class in Flex 3
: #FFFFCC; } .style2 { background-color: #FFFFCC; } Dynamic Class In Flex... at run time when you create an object of the class. This all can be achieved using "dynamic" keyword while creating class. DynamicClass.as
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    
Java Programming: Chapter 3 Quiz
Quiz Questions For Chapter 3 THIS PAGE CONTAINS A SAMPLE quiz on material from Chapter 3 of this on-line Java textbook. You should be able to answer these questions after studying that chapter. Sample answers to all
Java write file
. In the example subclasses of  Writer abstract class are used to write... class.           Write_File... Java write file      
Transaction in last 3 months
Transaction in last 3 months  I have a project in which i have to calculate amount submitted through transactions in last three months. I have... submitted. What query can i use to get all the transactions in past 3 months starting
@configuration annotation in Spring 3
@configuration annotation in Spring 3  doesn't make code tight coupling..? if we keep that in IOC in XML form, its deployment free for some kind of change management right?.   Please visit the following link: http
upload the text file through html and insert those data into the table
upload the text file through html and insert those data into the table ... into table.now i want to upload the text file through html and insert those data into the table.for this i want to write servlet program.can anyone helpme how to write
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
Entity Relationship Diagram 3
Entity Relationship Diagram 3  Task 3 Activities: Identify all entities and attributes from the given scenario. Draw entity relationship diagram of the given from scenario. Determine primary key and foreign keys from given
an overview of ejb 3
An overview of EJB 3. As we know that EJB architecture has failed in keeping the promise of increased productivity whereas EJB 3.0 has succeeded in doing so. It has reduced the complexity for the developers. It has succeeded in reducing
C++ question 3
C++ question - add the two matrices and display the elements of resultant matrix.   Write a program to accept from user elements of two 2x3 matrices. Then add the two matrices and display the elements of resultant matrix
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 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
reading the records from a .xlsx file and storing those records in database table
reading the records from a .xlsx file and storing those records in database... file and store that records in database table. I tried like this public class...*; public class ReadExcelFile{ public static void main(String[] args)throws Exception
OOP with Java 3 - Java Beginners
OOP with Java 3  Write a Temperature class that has two instances... for the scale, wither C for Celsius or F for Fahrenheit. the class should have four... Fahrenheit, use the following formulas to write the two methods degreeC = 5(degreeF
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
class
class  Is a class a subclass of itself
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
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
Advertisements
 

 

 

DMCA.com