Discussion about JAVA Programming
130 subscribers
10 photos
2 videos
152 files
12 links
Java + DSA Practices ( Daily Fever ) 😎
Daily Mission - 1 question per day
Download Telegram
/Decimal to binary
public static void DecimalToBin(int n){
int Mynum=n;
int pow=0;
int binary=0;
while(n>0){
int rem=n%2;
binary=binary+(rem*(int)Math.pow(10,pow));
pow++;
n=n/2;
}
System.out.println("The binary of "+Mynum+"="+binary);

}
public static void main(String[] args) {
DecimalToBin(7);
}
Write a Java method to compute the averageof three numbers.

public static int Average(int a, int b, int c){
int avg=(a+b+c)/3;
return avg;
}
public static void main(String[] args) {
int a=10;
int b=12;
int c=3;
int result=Average(a, b, c);
System.out.println(result);
}
WriteamethodnamedisEventhatacceptsanintargument.Themethodshouldreturntrueiftheargumentiseven,orfalseotherwise.Alsowriteaprogramtotestyourmethod


public static boolean isEven(int n){
if(n%2==0){
return true;
}
return false;
}
public static void main(String[] args) {
System.out.println(isEven(9));
}
Today's 5 Questions 🎯
public static int sum(int n){
int sum=0;
while(n>0){
int lastDigit = n%10;
sum= sum+lastDigit;
n=n/10;
}
return sum;

}
public static void main(String[] args) {
int n=78555;
int res=sum(n);
System.out.println(res);


}

Write a Java method to compute the sum of the digits in an integer.(Hint: Approach this question in the following way:a.Take a variable sum = 0b.Find the last digit of the numberc.Add it to the sumd.Repeat a & b until the number becomes 0 )
❤1
Try to solve this question 👉👉
Today's 5 Questions 🎯