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

 
 


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

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 Pages:
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
questions
to check whether entered no. ends with 5 or not 3. write a program to find minimum of 3 nos using nested if else. 4. write a program to check whether... calculator 2. write a program to print no of days in a given month Q. 3
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   
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
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
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
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
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    
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
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
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
Lost Using Swing Components(3)
Lost Using Swing Components(3)  Hello, I sound like every other newbie but I desperately need help. I have to write an application for the WebBuy... java.awt.*; import java.awt.event.*; public class JEMail extends JFrame implements
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 Programming: Chapter 3 Exercises
Programming Exercises For Chapter 3 THIS PAGE CONTAINS programming exercises based on material from Chapter 3 of this on-line Java textbook... by hand. Write a computer program that simulates the experiment. The program
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
Interview Question - Java Interview Questions
shall it prints or not? 2)Write a program in java to read a file & write in to another file? 3)Write a program taking two arrays and compare those two...*; import java.util.regex.*; public class ReadFile{ public static void main(String
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
Write Full concept of abstract class
Write Full concept of abstract class  Abstract class
write program - Java Beginners
write program  write a java program that will read the values... for Matrix Multiplication : class MatrixMultiplication{ public static void...[][] = {{6,4},{5,7},{1,1}}; int array2[][] = new int[3][3]; int x
write following program
write following program  Q1 What is the difference between single...-threading. Explain with examples Q2 Write a java applet that takes your name through a parameter from the HTML file and displays it Q3 Write a short note
write a program in java.
write a program in java.  arrange the natural n umber in 5x5 matrix as 21 22 23 24 25 20 7 8 9 10 19 6 1 2 11 18 5 4 3 12 17 16 15 14 13 i...; public class NumberSpiral{ public static void main(String[] args) { int n=5
Corejava Interview,Corejava questions,Corejava Interview Questions,Corejava
different behavior is required, you only require to write a class implementing... is used only at those places where the user requires only one instance of a class... Core Java Interview Questions Page1   
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
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
Difficult Interview Questions Page -3
Difficult Interview Questions Page -3       Question 21: How would you evaluate your present firm... and definitely I wont be repeat it again in the future. Those faults made me too
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
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
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
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
how to read the values for text and csv files and store those values into database in multiple rows..means one value for one row
how to read the values for text and csv files and store those values... (Servlet) 3. confirm.jsp 4. UpdateDB.java (Servlet) 5. error.jsp 6. namelist.csv... javax.servlet.http.HttpServletResponse; /** * Servlet implementation class UploadServlet */ public 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
Threads - Java Interview Questions
to Runnable Interface. 3)Using Runnable Interface, you can run the class several...Threads  creating a thread is two ways?extends with thread class and implements runnabule interface. What is the diffrence between those two?which
Java Write To File CSV
Java Write To File CSV In this tutorial you will learn how to write to file... a simple example which will demonstrate you how to write to csv file. To achieve... into which I have passed a file name to write a stream of characters. Next I
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
Servlets - Java Interview Questions
Servlets  write an application to print "Hello,user name"where Hello... javax.servlet.http.*; public class PostServlet extends HttpServlet{ public void... ) { out.println (""); } } } 3)web.xml PostServlet PostServlet
java - Java Interview Questions
java  can you write a java pro with out using static infront of main... be accessed outside the class / package * static: You need not have an instance of the class to access the method * void: Your application need
Java: Method Exercises 3
// Date : 3 May 2005 import javax.swing.*; class MethodExercises3... Java: Method Exercises 3 Name: _________________________________ What... 2 3 4 5 6 7 8 9 10 11
arrays - Java Interview Questions
? 3)Write a program that taking array values from keyboard? And should return...arrays  1)write a program that take integer array as input and find... two array A & B and B has same elements same as A but one element missing? Write
Given a list of responsibilities related to exceptions, identify those which are the bean provider's, and those which are the responsibility of the container provider. Be prepared to recog
those which are the bean provider's, and those which are the responsibility...; Given a list of responsibilities related to exceptions, identify those which are the bean provider's, and those which are the responsibility
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
java - Java Interview Questions
those bytecodes into native machine code. It executes through JVM which... the ".java" file and converted into .class file which is byte code. This byte have capablility to run on any Operating System e.g Window,Linux. It follows "Write
java - Java Interview Questions
. 3. protected: This modifier makes a member of the class available to all... a package, class, interface, method, or variable. It allows a programmer..., the return types of overloaded methods can be the same or different. Class
The Beginners Guide to JAXB part 3
*; import java.io.*; import generated.*; class lesson { public static void...) This sample application demonstrates how to use the ObjectFactory class to create... of the generated impl class methods signatures to contain the "synchronized"
Spring 3 MVC and Hibernate 3 Example Part 3
will be used in controller class. package ... This is the implementation class of ArticleService Interface. It defines all... to auto wire its instance in controller class. @Transactional annotation is used
help me in these - Java Interview Questions
plz answer me it is important to me and these are the questions : 1)Write... by dots and the total legth of the line is 30?? 3) Write a program that asks...; 3) import java.util.*; public class StringEx { public static void main
Read Write
and write to one text file   Java Read Multiple Files and store the data... java.util.jar.*; class OnlyExt implements FilenameFilter{ String ext; public OnlyExt... name){ return name.endsWith(ext); } } public class ReadMultipleFiles{ public

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.