Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |

#1
March 5th, 2013, 05:14 PM
 Life_Student
Contributing User

Join Date: Mar 2013
Posts: 41
Time spent in forums: 16 h 8 m 19 sec
Reputation Power: 1
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
March 5th, 2013, 06:08 PM
 Life_Student
Contributing User

Join Date: Mar 2013
Posts: 41
Time spent in forums: 16 h 8 m 19 sec
Reputation Power: 1
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);
}
}

}}

#3
March 5th, 2013, 06:16 PM
 Life_Student
Contributing User

Join Date: Mar 2013
Posts: 41
Time spent in forums: 16 h 8 m 19 sec
Reputation Power: 1
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));
}
}

}}

#4
March 5th, 2013, 06:23 PM
 Life_Student
Contributing User

Join Date: Mar 2013
Posts: 41
Time spent in forums: 16 h 8 m 19 sec
Reputation Power: 1
not sure this is right

when i run this program with the sqrt function it lists 30, and 90 twice anyreasons why?

#5
March 5th, 2013, 06:30 PM
 burakaltr
Contributing User

Join Date: Feb 2013
Posts: 46
Time spent in forums: 9 h 58 m 37 sec
Reputation 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();
}

}```

#6
March 5th, 2013, 06:40 PM
 Life_Student
Contributing User

Join Date: Mar 2013
Posts: 41
Time spent in forums: 16 h 8 m 19 sec
Reputation Power: 1
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));
}
}

}

#7
March 5th, 2013, 06:46 PM
 burakaltr
Contributing User

Join Date: Feb 2013
Posts: 46
Time spent in forums: 9 h 58 m 37 sec
Reputation 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));

}

}

 Viewing: Dev Shed Forums > Programming Languages > Java Help > Newbie help