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



Home Answers Viewqa Java-Beginners shifting values

Have Programming Question? Ask it here!
 
 
 


shreyasi das
shifting values
1 Answer(s)      4 years and 9 months ago
Posted in : Java Beginners



Advertisement
View Answers

November 14, 2009 at 4:52 PM


Hi Friend,

Try the following code:

import java.util.Scanner;
public class ShiftArrayValues{
public static void main(String[] args) {
int[] array = new int[10];
System.out.println("Enter 10 numbers");
Scanner input=new Scanner(System.in);
for(int i=0;i<array.length;i++){
array[i]=input.nextInt();
}
System.out.println("Original array is:");
printArray(array);
System.out.println();
System.out.println("Left of Right");
String st=input.next();
System.out.println("Enter an amount by which to rotate the array");
int amount = input.nextInt();
if(st.equals("Left")){
shiftLeft(array,amount);
printArray(array);
}
else if(st.equals("Right")){
shiftRight(array,amount);
printArray(array);
}
}
public static void shiftLeft(int[] array, int amount){
for( int j=0; j<amount; j++) {
int a = array[0];
int i;
for(i = 0; i < array.length-1; i++)
array[i] = array[i+1];
array[i]= a;
}
}
public static void shiftRight(int[] array, int amount) {
for( int j=0; j<amount; j++) {
int a = array[array.length-1];
int i;
for(i = array.length-1; i > 0; i--)
array[i] = array[i-1];
array[i]= a;
}
}
public static void printArray(int[] array) {
for(int x=0; x<array.length; x++) {
System.out.print(array[x] + " ");
}
System.out.println();
}
}

Thanks


Related Tutorials/Questions & Answers:
shifting values - Java Beginners
shifting values  write a program to shift the array values in a circular way according to user's choice. user will supply the size of the array,array... of shifting(right or left). use try/catch. and a function for shifting  
Shifting txt file to database - Java Beginners
Shifting txt file to database   Question Details: I want to shift data from txt file to Database. The data is written in the following text format. Record No. = 0001 Name : Abdul Rauf Designation
Advertisements
duplicate values
duplicate values  My database having cursor that has duplicate values.i want to remove duplicate values through java application
reain values
if it already exits i m using reuest.sendredirect to same jsp but all textbox values are cleard, i want to retain all values in textboxs after request.sendredirect .Please
Values to listbox
Values to listbox  I have two textboxes by the name street and city.I have an add button and a name listbox. When I enter street and city and press the add button ,all the names of the people residing there are listed in listbox
Retrive Values
Retrive Values  I want to retrive the values between the td by the id using the javascript.So please help me... html form like this <TABLE width="100%" bgColor=""> <TR> <TD ID="td1">Cell 1</TD>
Shifting Row Using JSP
Shifting row using JSP       In this program we are going to shift the row using java...; In this example, we first create 50 cells and then insert 50 values, then we shift rows
JTable duplicate values in row
JTable duplicate values in row  JTable duplicate values in row
Shifting from Ant to Maven
Shifting from Ant to Maven       Maven is entirely a different creature from Ant. Ant is simply a toolbox whereas Maven is about the application of patterns in order
multiple select values
multiple select values   can you provide an example for multiple select values for html:select tag
percentage values for <TD WIDTH=...>
percentage values for   Can I use percentage values for <TD WIDTH=...>
how to set the values in jsp
how to set the values in jsp  how to set the values text boxs in jsp frm dbase via servlet
Atomic values in Xml
Atomic values in Xml  Hi..... please give me the ans How you define atomic values in Xml? Thanks
disallow NULL values in a table.
disallow NULL values in a table.  How do I disallow NULL values in a table
Quotes around attribute values.
Quotes around attribute values.  Should I put quotes around attribute values
fetch values in dropdown
fetch values in dropdown  in my application i want fetch dropdown values in jsp page through servlet. means i have to fetch the database fields values in array variable of servlet and then i have to print those values in dropdown
retrive values - JSP-Servlet
retrive values  how to get multiple values from html to jsp
select tag multiple values
select tag multiple values   I want to insert multiple values in database which i have selected from select tag
Java plateform dependent values
Java plateform dependent values  How will you get the platform dependent values like line separator, path separator, etc., ?  we will get the the platform dependent values like line separator, path separator
Remove duplicate values
Remove duplicate values  i am trying to insert values into database... is primary key. other attributes can allow null. am trying to insert values...:subject],[CreatedBy])" + " values('"+Cname[i]+"','"+textdescription[i
passing values on button click
passing values on button click  Please help me to solve this issue.I want to pass a value assigned to button to another view upon button click in xcode
Retain jsp values
Retain jsp values  how to retain a jsp values without using session and cookies?   Hello Friend, You can use request.getParameter() and request.setAttribute() methods to get the jsp fields values. For more information
Default Values
Default Values The elements which do not have any children can have default values. Default values are assigned automatically if no value is supplied. The "default" attribute of the xs:element element can be used
passing values in hyperlink
passing values in hyperlink  Hi. I have given a hyperlink in one jsp page. Can i able to pass that hyperlink label as a value to the next page its navigating when the user clicks it. Plz respond me quickly. Thanks in advance
retaining textbox values
retaining textbox values  i have a calculator program, when i press a button the value displays but disappears when i press another button so how can i keep values to display when i press multiple buttons
passing values in hyperlink
passing values in hyperlink  Hi. I have given a hyperlink in one jsp page. Can i able to pass that hyperlink label as a value to the next page its navigating when the user clicks it. Plz respond me quickly. Thanks in advance
passing values in hyperlink
passing values in hyperlink  Hi. I have given a hyperlink in one jsp page. Can i able to pass that hyperlink label as a value to the next page its navigating when the user clicks it. Plz respond me quickly. Thanks in advance
passing values in hyperlink
passing values in hyperlink  Hi. I have given a hyperlink in one jsp page. Can i able to pass that hyperlink label as a value to the next page its navigating when the user clicks it. Plz respond me quickly. Thanks in advance
passing values in hyperlink
passing values in hyperlink  Hi. I have given a hyperlink in one jsp page. Can i able to pass that hyperlink label as a value to the next page its navigating when the user clicks it. Plz respond me quickly. Thanks in advance
retrive values - JSP-Servlet
retrive values  how to retrive multiple values from html to jsp  Hi Friend, Try the following code: 1)calljsp.html: Enter Name: Enter Address: Gender:MF Qualification: Btech MBA MCA MSC
iterating hashmap values in struts2
iterating hashmap values in struts2  hi, i am not getting how to display this map values in jsp page using struts2 public class ViewOperation2 { public Map<String,Object> viewCustDetails(){ Map<String
values in combobox - Java Beginners
values in combobox  how to fill values in combo box i.e. select tag in html using javascript?   Hi Friend, Try the following code: ComboBox var arr = new Array(); arr[0] = new Array("-select-"); arr[1
Replacing a template with actual values
holders with acutal value. The acutal values are in the map with key as the place
pass parameter names and values
pass parameter names and values  What is the <jsp:param> standard action?   The <jsp:param> standard action is used with <jsp:include> or <jsp:forward> to pass parameter names and values
retrieve multiple attribute values
; What I would like is to retrieve both the attribute values of process
retrieve multiple attribute values
like is to retrieve both the attribute values of process:Output during execution
retrieve multiple attribute values
like is to retrieve both the attribute values of process:Output during execution
Arraylist from row values
Arraylist from row values  Hello, can anyone please help on how to make an arraylist from the row values of a particular column from a database table? Thanks in advance!   import java.sql.*; import java.util.ArrayList
JTable values are not gettiing properly
JTable values are not gettiing properly  Sir, I created one JTable with two columns and one row i have given two values,but i getting only one value .That is a[1][1] is String array. if i have given 8,9 then i got 8 only
ma access reading values
values throught servlet and register.jsp now i need code for reading values from...(table in my ms access) need to display values in jsp .............please help me... and inserted values throught servlet and register.jsp now i need code for reading
insert values - JSP-Servlet
insert values  How to insert values in the oracle database using JSP. Plz tell the core answer as soon as possible .  HiThis is html...;insert user_details values('"+username+"','"+jobposition+"
passing values - JSP-Servlet
_DataInsertion(Name,Hallno,Time,Date,Mobileno,Status) values('"+name+"','"+hallno+"','"+time
Getting image pixel values
Getting image pixel values  how to get image pixels values on mouse click   import java.awt.*; import java.awt.event.*; import java.awt.image.BufferedImage; import java.io.*; import javax.swing.*; public class
ma access reading values
has to login . i already created ms access page and inserted values throught servlet and register.jsp now i need code for reading values from "username... access) need to display values in jsp .............please help me
form values in java script - Struts
form values in java script  how to get form values in java script functions with struts1.1
inserting dropdown values into database table
inserting dropdown values into database table   hi i want to insert dropdown values into a database table by using jsp
show the database values graphical represantation
show the database values graphical represantation   show the database values graphical represantation and auto refresh for every 30 secand displaying in webpage
PHP Array Count Values
of values, i.e. total number of appearance of an element, in an array. PHP provides array_count_values() function to count the number of variables.  General description of array_count_values() is given below: General Format
Hiding form values using ajax
Hiding form values using ajax  i am trying to show and hide form values with ajax but it's not working,but in javascript it is working.Can anyone will help me to the work in ajax please. Thanks in advance
how to insert a summary values in grid
how to insert a summary values in grid  how to insert a summary value in grid
 

 

 

DMCA.com