Thread: Newbie help

    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    41
    Rep Power
    2

    Newbie help


    hello Im new java and I am taking a class and am stuck on this example:
    write a program to print out values of square root of all integers divisible by 5 between 5 and 100.
    I dont understand how to check each number between 5 and 100 including those two to see if they are divisible by 5 and then im supposed to find the root for the numbers that were divisible by 5. Im very confused and not sure what to do any help would be appreciated
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    41
    Rep Power
    2

    what i have so far


    what i have so far

    public class RootInt {
    public static void main(String args[]) {
    for(int i=5; i<=100; i++){
    for(int j=5; i%j==0; j++){

    System.out.println(i);
    }
    }

    }}
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    41
    Rep Power
    2

    is this right?


    I think i figured it out does this look right???


    public class RootInt {
    public static void main(String args[]) {
    for(int i=5; i<=100; i++){
    for(int j=5; i%j==0; j++){

    System.out.println(Math.sqrt(i));
    }
    }

    }}
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    41
    Rep Power
    2

    not sure this is right


    when i run this program with the sqrt function it lists 30, and 90 twice anyreasons why?
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    47
    Rep Power
    0
    Code:
    public class Root {
    
    	public Root() {
    		// TODO Auto-generated constructor stub
    		for(int i=5;i<=100;i+=5){
    			System.out.println(Math.sqrt(i));
    			
    			
    		}
    	}
    
    	/**
    	 * @param args
    	 */
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    new Root();
    	}
    
    }
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    41
    Rep Power
    2
    thanks for that this is what i got now:


    public class RootInt {
    public static void main(String args[]) {
    for(int i=5;i<=100;i+=5){


    System.out.println("The values of square root for " + i + ": "+ Math.sqrt(i));
    }
    }

    }
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    47
    Rep Power
    0
    TRY



    public class RootInt {
    public static void main(String args[]) {
    for(int i=5;i<=100;i+=5)System.out.println("The values of square root for " + i + ": "+ Math.sqrt(i));

    }

    }

IMN logo majestic logo threadwatch logo seochat tools logo