Activity Stream
48,167 MEMBERS
6883 ONLINE
besthostingforums On YouTube Subscribe to our Newsletter besthostingforums On Twitter besthostingforums On Facebook besthostingforums On facebook groups

Page 1 of 2 12 LastLast
Results 1 to 10 of 11
  1.     
    #1
    Member

    Default 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();
    }
    }
    }
    Its only a code for outputing the user input. but Im stuck on how to put sum in every colum and row..

    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

  2.   Sponsored Links

  3.     
    #2
    Member
    Website'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;
            }
        }
    }

  4.     
    #3
    Member
    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]);
    	}
    
    }

  5.     
    #4
    Member
    any1 can help me in this please?

  6.     
    #5
    Respected 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.

  7.     
    #6
    Member
    Website's:
    MovDra.com 18Scenes.com iduntknowwhy.info
    here for
    first question, it's very easy
    i think you already solve it
    for second question, you just need use do while + in case

  8.     
    #7
    Member
    Website's:
    MovDra.com 18Scenes.com iduntknowwhy.info
    Code: 
    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]);
                }
            }
            
    	}
    }
    this source code will show output like u say
    array length are fixed
    if u want add or remove the length of array then u must use arraylist

  9.     
    #8
    Member
    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?

  10.     
    #9
    Member
    Website's:
    MovDra.com 18Scenes.com iduntknowwhy.info
    use arraylist
    then you dont need to declare the length
    so user can input as much as they want

  11.     
    #10
    Member
    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();
    }
    }
    thank you.

Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Java stinks: Turn off your Java browser plugin
    By Loget in forum General Discussion
    Replies: 37
    Last Post: 5th Sep 2012, 07:40 AM
  2. please help me in java
    By shanshayan in forum Webmaster Discussion
    Replies: 2
    Last Post: 10th Jan 2012, 06:48 AM
  3. HELP: Java countdown
    By CuraHack in forum Web Development Area
    Replies: 4
    Last Post: 9th Nov 2011, 02:42 AM
  4. In need of JAVA Developer
    By avngr in forum Web Development Area
    Replies: 2
    Last Post: 1st Sep 2011, 02:44 PM
  5. Some help need in Java programing
    By bapi21 in forum Web Development Area
    Replies: 1
    Last Post: 10th Jul 2011, 01:08 PM

Tags for this Thread

BE SOCIAL