Results 1 to 10 of 11
-
4th Dec 2011, 10:48 AM #1OPMember
Need help in JAVA
Code:import java.io.*; public class array { public static InputStreamReader digi = new InputStreamReader (System.in); public static BufferedReader cool = new BufferedReader (digi); public static void main (String[] args) throws Exception { System.out.print("Number of rows? "); int b = Integer.parseInt(cool.readLine()); System.out.print("Number of columns? "); int c = Integer.parseInt(cool.readLine()); int a[][]=new int [b][c]; for (int row=0;row<b;row++) { for (int col=0;col<c;col++){ System.out.print("Element ["+row+"]["+col+"]: "); a[row][col]=Integer.parseInt(cool.readLine()); } } for (int x=0;x<b;x++) { for (int y=0;y<c;y++){ System.out.print(a[x][y]+"\t"); } System.out.println(); } } }
like this output..
Number of row? 2
Number of column? 2
3 5 = 8
4 6 = 10
= =
7 11
sumething like that?digimon Reviewed by digimon on . Need help in JAVA import java.io.*; public class array { public static InputStreamReader digi = new InputStreamReader (System.in); public static BufferedReader cool = new BufferedReader (digi); public static void main (String args) throws Exception { System.out.print("Number of rows? "); int b = Integer.parseInt(cool.readLine()); Rating: 5
-
4th Dec 2011, 11:46 AM #2MemberWebsite's:
imdber.org justpaste.me// May i ask why u instantiated outside the main method when u can instantiate it inside?
Code:import java.io.*; public class ArrayTest { public static void main(String[] args)throws IOException{ BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); int y=0; int x=0; int row=0; int col=0; System.out.print("Number of rows: "); int a = Integer.parseInt(bf.readLine()); System.out.print("Number of columns: "); int b = Integer.parseInt(bf.readLine()); int array[][] = new int[a][b]; for(x=0; x<array.length;x++){ for(y=0; y<array[x].length;y++){ System.out.print("Enter element ["+x+"]["+y+"]: "); array[x][y]=Integer.parseInt(bf.readLine()); } } for(x=0;x<array.length;x++){ for(y=0;y<array[x].length;y++){ System.out.print(array[x][y]+" "); row+=array[x][y]; } System.out.println("= "+row); row=0; } for(y=0;y<array[a-1].length;y++){ System.out.print("= "); } System.out.println(); for(y=0;y<array[a-1].length;y++){ for(x=0; x<array.length;x++){ col+=array[x][y]; } System.out.print(col+" "); col=0; } } }
-
13th Dec 2011, 06:48 PM #3OPMember
I need help again please about manipulating simple arrays..
well here's the output I'm trying to make..the program when run will do the following..
Enter a number? (example 5)
Do you want to Enter Again?
1-Yes
2-No (When 2 is selected it will output 5)
Lets think the user Selected 1.
//It will ask again.
Enter a number? (Example input 4)
Do you want to Enter Again?
1-Yes
2-No
//Selected number 2
It will output..
5
4
thats it.. please help..
here's my code which is a mess.. lol.. please englihten me..
Code:import java.io.*; public class array { public static void main(String[] args) throws Exception { public static InputStreamReader shet = new InputStreamReader (System.in); public static BufferedReader cool = new BufferedReader (shet); int a; int b=0; int c=0; int d=1; int array1[] = new int [1]; int array2[] = new int [1]; do { System.out.print("Enter a number? "); a = Integer.parseInt(cool.readLine()); if (d==1) { array1[b]=a; array2[c]=array1[b]; array1 = new int [c+1]; array1[b]=array2[c]; } System.out.println("Do you want to add more? "); System.out.println("1-yes"); System.out.println("2-no"); d = Integer.parseInt(cool.readLine()); if(d!=1) { System.out.println("All number Entered"); for (int x=0;x<array1.length;x++) { System.out.println(array1[x]); } } }while ( d==1); System.out.println(array1[0]); } }
-
29th Dec 2011, 03:40 AM #4OPMember
any1 can help me in this please?
-
29th Dec 2011, 04:10 PM #5Respected Member
Hmm. You asked in the first post how to get totals for each column & row. Then the second post you asked to get simple single line output of numbers entered.
Which question is the real question? I am confused on what you need.
-
29th Dec 2011, 06:14 PM #6MemberWebsite's:
MovDra.com 18Scenes.com iduntknowwhy.infohere for
first question, it's very easy
i think you already solve it
for second question, you just need use do while + in case
-
29th Dec 2011, 06:48 PM #7MemberWebsite's:
MovDra.com 18Scenes.com iduntknowwhy.infoCode:import java.io.*; import java.util.Scanner; public class Array { public static void main(String[] args){ Scanner sc = new Scanner(System.in); int a; int b = 0; int c = 0; int d = 1; int array1[] = new int[10]; int i = 0; do{ System.out.print("Enter a number? "); a = sc.nextInt(); array1[i] = a; System.out.println("Do you want to add more? "); System.out.println("1-yes"); System.out.println("2-no"); d = sc.nextInt(); if (d==1){ i++; } }while ( d == 1); int asd = array1.length; //last print all entered number System.out.println("All number Entered"); for(int x = 0 ;x<asd;x++){ if(array1[x]!=0){ System.out.println(array1[x]); } } } }
array length are fixed
if u want add or remove the length of array then u must use arraylist
-
1st Jan 2012, 06:32 AM #8OPMember
yes this is the exactly what I nee.. but the problem is the limit is 10 only.. how to make it unlimited till the user choose 2? or No?
-
1st Jan 2012, 06:36 AM #9MemberWebsite's:
MovDra.com 18Scenes.com iduntknowwhy.infouse arraylist
then you dont need to declare the length
so user can input as much as they want
-
20th Jan 2012, 03:51 AM #10OPMember
hello there again guys its been months I been learning java..
can any1 please make this code do it step by step please instead of putting the output directly.. I mean I need the code to output step by step.
Code:class Bubble { public static void main(String args[]) { int arr1[] = {10,90,48,58}; for (int i=0;i<arr1.length;i++) System.out.print(arr1[i]+ "\t"); for(int i=0;i<(arr1.length-1);i++) { for (int j=i+1;j<arr1.length;j++) { if(arr1[i]>arr1[j]) { int x,y; x=arr1[i]; y=arr1[j]; arr1[i] = y; arr1[j] = x; } } } System.out.println("\n"); System.out.println("Array after sorting in ascending order"); for (int i=0;i<arr1.length;i++) { System.out.print(arr1[i]+ "\t"); } System.out.println(); } }
Sponsored Links
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Similar Threads
-
Java stinks: Turn off your Java browser plugin
By Loget in forum General DiscussionReplies: 37Last Post: 5th Sep 2012, 07:40 AM -
please help me in java
By shanshayan in forum Webmaster DiscussionReplies: 2Last Post: 10th Jan 2012, 06:48 AM -
HELP: Java countdown
By CuraHack in forum Web Development AreaReplies: 4Last Post: 9th Nov 2011, 02:42 AM -
In need of JAVA Developer
By avngr in forum Web Development AreaReplies: 2Last Post: 1st Sep 2011, 02:44 PM -
Some help need in Java programing
By bapi21 in forum Web Development AreaReplies: 1Last Post: 10th Jul 2011, 01:08 PM
themaCreator - create posts from...
Version 3.24 released. Open older version (or...