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



Home Answers Viewqa Java-Beginners arry based problem

Have Programming Question? Ask it here!
 
 
 


moni sharma
arry based problem
1 Answer(s)      3 years and 4 months ago
Posted in : Java Beginners


{modify this proram in such a way so that it can take input int and char both .and also modify so that input can be given at run time.}

public class Insertion{

public static void main(String a[]){
 int i;
 int array[]={17,12,3,6,4,19,200};

System.out.println("       Selection Sort\n\n");   
System.out.println("Values Before the sort:\n");    
for(i = 0; i < array.length; i++)

 System.out.print( array[i]+"  ");
System.out.println();

insertion_srt(array, array.length);        
System.out.print("Values after the sort:\n");    
for(i = 0; i <array.length; i++)
System.out.print(array[i]+"  ");
System.out.println();  

System.out.println("PAUSE");

}

  public static void insertion_srt(int array[],int n){
   for (int j = 0; j < n; j++){
   int i = j-1;
   int k = array[j];
   while ((i>= 0) && (array[i] > k)){
    array[i+1]=array[i];
     i=i-1;
    array[i+1]=k;
     }}
 }

}


Advertisement
View Answers

January 4, 2011 at 5:19 PM


Hi Friend,

We have modified your code.

import java.util.*;
public class Insertion
{
public static void insertion_srt(int array[],int n){
   for (int j = 0; j < n; j++){
   int i = j-1;
   int k = array[j];
   while ((i>= 0) && (array[i] > k)){
    array[i+1]=array[i];
     i=i-1;
    array[i+1]=k;
     }
     }
 }
public static void main(String a[]){
    Scanner input=new Scanner(System.in);
    int array[]=new int[5];
 int i;


System.out.println("       Selection Sort\n\n");   
System.out.println("Values Before the sort:\n");    
for(i = 0; i < array.length; i++){
array[i]=input.nextInt();
}
for(i = 0; i < array.length; i++){
System.out.println(array[i]);
}

insertion_srt(array, array.length);        
System.out.print("Values after the sort:\n");    
for(i = 0; i <array.length; i++)
System.out.print(array[i]+"  ");
System.out.println();  

System.out.println("PAUSE");
}
}

Thanks



Related Tutorials/Questions & Answers:
arry based problem
arry based problem  how to put char type & int types variable in same array.and also what the procedure for giving input to those array at run time
arry based problem
arry based problem  how to put char type & int types variable in same array.and also what the procedure for giving input to those array at run time
Advertisements
arry based problem
arry based problem  {modify this proram in such a way so that it can take input int and char both .and also modify so that input can be given at run time.} public class Insertion{ public static void main(String a[]){ int i
arry based problem
arry based problem  {modify this proram in such a way so that it can take input int and char both .and also modify so that input can be given at run time.} public class Insertion{ public static void main(String a[]){ int i
arry based problem
arry based problem  {modify this proram in such a way so that it can take input int and char both .and also modify so that input can be given at run time.} public class Insertion{ public static void main(String a[]){ int i
arry based problem
arry based problem  {modify this proram in such a way so that it can take input int and char both .and also modify so that input can be given at run time.} public class Insertion{ public static void main(String a[]){ int i
Array /string based problem....
Array /string based problem....  thanx to help me.but again a problem is here that it sorts single char as (a,b,c,n,m)but not the string .and also... solve this problem also as soon as possible..... import java.util.*; public class
string array based problem
string array based problem  R/sir, firstly thanks to help me so much. but now it can sort string very well but in case of integers... sorted value: 11 12 13 3 this is the problem here...... import java.util.*; public
array and string based problem
array and string based problem  this program is accepting only integers as input but i want to modify it such that it can accept both integers and char. import java.util.*; public class Insertion1 { public static void insertion
array and string based problem
array and string based problem  this program is accepting only integers as input but i want to modify it such that it can accept both integers and char. import java.util.*; public class Insertion1 { public static void insertion
array and string based problem
array and string based problem  this program is accepting only integers as input but i want to modify it such that it can accept both integers and char. import java.util.*; public class Insertion1 { public static void insertion
based on C#
based on the Criteria given below: a) When user will not enter Employee Name... discounts based on the following items. i. CRT monitors attract 10% discount... enter LCD, ask the user to enter the size. Based on the size entered by the user
problem on strings
problem on strings  in string1 "123456 ABC DEF...",IN string2 "raveen". iwant to add string2 after 123456 in the first string based on index number.i need logic for this with out using StringBuffer concept. Thanks in advanace
alidation based on the xml in validation.xml.
alidation based on the xml in validation.xml.  How you will enable front-end validation based on the xml in validation.xml
Web based Project
Web based Project  Can anyone please help me by providing certain code for web based project relating to employee payroll system and attendance management
java based question
java based question  1,2,c,Z,A,5,2,1,A,C,D,Y,X,9,3,2 separate numbers and alphabets using collection and output will ascending order
YUI Based Lightbox
YUI Based Lightbox       a YUI based image gallery script Read full Description
Based on struts Upload - Struts
Based on struts Upload  hi, i can upload the file in struts but i want the example how to delete uploaded file.Can you please give the code
Internet Based Application
Internet Based Application  Write an Internet based application in J2ME that parses and saves the HTML source. The application should do the following: Allow the user to enter a HTML URL into a TextField as part of a form (use
java based question
java based question  if there is a site and after user login on the right top there is a button of logout and i want to display firstname and lastname of the user after login then in what class i have to do changes?? and what
component based technology - EJB
component based technology  main concept behind ejb  Hi Friend, Enterprise JavaBeans (EJBs) are used in distributed applications that contains the application's business logic and live business data. EJB addresses
java program based on array
java program based on array  write a program to create an array of 10 integers in main.accept values from the user in that array .now again ask the use another nomber and pass the array and the no. entered to function called
Web-based system development
Web-based system development  I have a system written in java application.my lecturer asks me to do in web-base. what should i do?what should i have and what should i know? i have read that the best architecture is 3-tier
EJB based application
EJB based application  Project description The project has two separate parts, the client GUI application and the server application. The Client GUI This component must consist of a data capture screen that provides
problem in onlinetest...
problem in onlinetest...  hi, my code getting the problem is ,when user leave a question then the server puts error... pls help me
problem in validation
problem in validation  sir/madam, i m using struts-1.3.10. i m getting a problem my properties file is not found.... while i hav configuired it in struts-config.xml file, like thanks n regards himanshu
javascript problem
javascript problem  hi guys My problem is that I am using radio button for yes or no but i want to do that if I press yes button then enter... enter please help me this problem
Problem with loginbean.jsp
Problem with loginbean.jsp  http://www.roseindia.net/jsp/loginbean.shtml - I am getting an error in loginbean.jsp.There is some error regarding .What is hello in this? Also in this example how
compilation problem
compilation problem  struts 2.0 : i have included all 5 jars in lib folder,but its giving compilation problem that package open symphony doesnot... havenot set the build path.if this is the problem then tell me how to set
compilation problem
compilation problem  struts 2.0 : i have included all 5 jars in lib folder,but its giving compilation problem that package open symphony doesnot... havenot set the build path.if this is the problem then tell me how to set
Problem with cookies
Problem with cookies  Hello All, i need jsp code for RememberMe module of login. i am facing problem with cookies. so please if any one could guide me please help and provide mme the exact code.   Please visit
problem with package
problem with package  Dear sir, i have created one java file with package com.net; and i compiled the program.it showing the .class file in " net" folder.The problem is i want to use that .class file in some other
Oracle9i Problem
Oracle9i Problem  Hi I have a problem in Oracle9i .I have... the table what i created .But after closing the SQL+ ,the problem started.When i... .....;.it is saying no rows are selected.Why the problem arised in not getting the data that i
problem with session.invalidate()
problem with session.invalidate()  i stuck by a line with "session.invalidate()", after user logout also by pressing the back button of the browser user is still able to navigate to his home page and able to view the session
JScrollBar Problem...
JScrollBar Problem...  Hello Sir/mam, Can i know how to use JScrollBar to JFrame without adding any JPanel to it.. i want to add JScrollBar Directly to JFrame... Please Provide me Simple Example so i can understand
problem on php
problem on php   l have five tables and build them as forms and link between them php and database and i want to build query between them plz help me soon   PHP MySQL Tutorials
URL problem
URL problem  Hi. I have created a webpage for my project website. in that i have used frameset to split the page. Now if i click any link in the page its navigating to the another page. but the problem is here in the url its
Skyline Problem
is the line tracing the largest y value from any rectangle in S The Problem: Write.... Your method should solve the problem three different ways; each solution
Problem in Array
Problem in Array  Hi, Can you help me with this problem? Run a program that check if the input string contains equal number of A's and B's. Hoping for your answer.Thank you.   Here is an example that check
PROBLEM IDENTIFICATION
PROBLEM IDENTIFICATION  class MOrders { int nooforders; // Data members of the class public int getorder() { nooforders = 500; } public void displayorders() { System.out.println("The number of orders to be delivered
problem in coding
problem in coding  i have a following code which display the contents of the text file but not other program like java or any c program is there any handler to open the program files other than Filereader. FileReader fr = new
problem in html
problem in html  i want that my custmer can upload file or video on my website so plz help and send me the code which i can paste on my web site so people can upload their video and img and plz send the html code becaz my web
HttpSession problem :(
HttpSession problem :(  i want to ask that do i need to define httpsession in every servlet or jsp in my web application? if yes, then on which servlet? the very first one like my welcome page which comes after login page
Problem in enctype=
Problem in enctype=  im using a page which is in JSP. i have some text boxes and one upload button. i want to load the file itself when i click.... but the problem is the uploaded file is not stored in the prefered folder. i printed
 

 

 

DMCA.com