Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: I want print the number which leaves remainder 0 . For example: if 8 is enter I want output 1248 . Tell me where I'm making mistake

  1. #1
    Junior Member
    Join Date
    Apr 2022
    Location
    India
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default I want print the number which leaves remainder 0 . For example: if 8 is enter I want output 1248 . Tell me where I'm making mistake

    public class Main {
    	public static void main(String[] args) {
    		Scanner scan = new Scanner(System.in);
    		System.out.println("Enter a Number : ");
    		int input = scan.nextInt();
     
    		int array[] = new int[10];
    		int j=0;
    		int x = 0;
     
    		for (int i = 1; i <= input ; i++){
    		        j += 1;
    		        if (input % j == 0){
    		            array[x++] = j ;
    		        }
    		}
     
    		System.out.println("the number divisble by: ");
    		for (int k:array){
    		        if (k != 0){
    		            System.out.print(array[k]);
    		       }
    		}
     
     
    	}
    }[COLOR="Silver"]
     
    --- Update ---
     
    [/COLOR]public class Main {
    	public static void main(String[] args) {
    		Scanner scan = new Scanner(System.in);
    		System.out.println("Enter a Number : ");
    		int input = scan.nextInt();
     
    		int array[] = new int[10];
    		int j=0;
    		int x = 0;
     
    		for (int i = 1; i <= input ; i++){
    		        j += 1;
    		        if (input % j == 0){
    		            array[x++] = j ;
    		        }
    		}
     
    		System.out.println("the number divisble by: ");
    		for (int k:array){
    		        if (k != 0){
    		            System.out.print(array[k]);
    		       }
    		}
     
     
    	}
    }


    --- Update ---

    import java.util.Scanner;

    public class Main {
    public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    System.out.println("Enter a Number : ");
    int input = scan.nextInt();

    for ( int i = 1 ; i<=input ; i++){
    if ( input%i == 0 ){
    System.out.println(i);
    }
    }

    }
    }
    Last edited by Norm; April 10th, 2022 at 01:55 PM. Reason: Removed spaces in first code tag; changed \ to /

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: I want print the number which leaves remainder 0 . For example: if 8 is enter I want output 1248 . Tell me where I'm making mistake

    I want print the number which leaves remainder 0
    What problems are you having?

    Do you have the steps the program needs to take to solve that problem? The algorithm

    Can you post the steps the program needs to take?

    How are you debugging the code to see what values is using and seeing?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member
    Join Date
    Apr 2022
    Posts
    36
    Thanks
    0
    Thanked 8 Times in 8 Posts

    Default Re: I want print the number which leaves remainder 0 . For example: if 8 is enter I want output 1248 . Tell me where I'm making mistake

    import java.util.Scanner;
     
    public class Main {
        public static void main(String[] args) {
    	Scanner scan = new Scanner(System.in);
    	System.out.print("Enter a Number : ");
    	int input = scan.nextInt();
     
            int array[] = new int[10];
    	int x = 0;
     
    	for (int i = 1; i <= input; i++){
                if (input % i == 0){
    		array[x++] = i;
                }
            }
     
            for (int i = 0; i < x; i++){
                System.out.println(array[i]);
            }
        }
    }
    Last edited by andreaita44; April 18th, 2022 at 09:48 AM.

Similar Threads

  1. cannot enter a floating point number
    By Tedstriker in forum What's Wrong With My Code?
    Replies: 3
    Last Post: July 5th, 2013, 06:37 PM
  2. Replies: 1
    Last Post: December 3rd, 2012, 02:35 PM
  3. How To Ask the User to Enter Another Number Using the Number 1
    By Pettsa in forum Object Oriented Programming
    Replies: 6
    Last Post: May 3rd, 2012, 03:44 AM
  4. I am making a silly mistake but I cant find where! PLEASE HELP!
    By akmi5 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: April 14th, 2012, 01:44 AM
  5. i dont know why i cant see the output nor enter input
    By Newbiesss in forum What's Wrong With My Code?
    Replies: 2
    Last Post: June 1st, 2011, 12:41 PM

Tags for this Thread