8 תשובות
צאט ציפיטי
מה השאלה?
שואל השאלה:
.
.
אנונימית
^
אני לא במחשב כרגע, עוד שעה בערך יעזור לך?
אני יכול לנסות מהטלפון גם פשוט ככה אין לי דרך לוודא שאין לי טעות
אני לא במחשב כרגע, עוד שעה בערך יעזור לך?
אני יכול לנסות מהטלפון גם פשוט ככה אין לי דרך לוודא שאין לי טעות
שואל השאלה:
.
.
אנונימית
שואל השאלה:
^
ברור תודה רבה
^
ברור תודה רבה
אנונימית
^
וואי סליחה שכחתי מזה, הנה זה לסעיפים 3 ו4 (זה כולל גם את סעיף 1 ו2, מקווה שהבנתי את השאלה נכון)
import java.util.scanner;
public class fourdigitnumber {
public static void main(string[] args) {
scanner scanner = new scanner(system.in);
system.out.print("enter a four-digit number: ");
int number = scanner.nextint();
system.out.println("the number is: " + number);
int digit1 = number / 1000;
int digit2 = (number / 100) % 10;
int digit3 = (number / 10) % 10;
int digit4 = number % 10;
// part a: largest digit
int largestdigit = math.max(math.max(digit1, digit2), math.max(digit3, digit4));
system.out.println("largest digit: " + largestdigit);
// part b: smallest digit
int smallestdigit = math.min(math.min(digit1, digit2), math.min(digit3, digit4));
system.out.println("smallest digit: " + smallestdigit);
// part c: average of digits
double average = (digit1 + digit2 + digit3 + digit4) / 4.0;
system.out.println("average of digits: " + average);
// part d: sum of squares of digits
int sumofsquares = (digit1 * digit1) + (digit2 * digit2) + (digit3 * digit3) + (digit4 * digit4);
system.out.println("sum of squares of digits: " + sumofsquares);
}
}
וואי סליחה שכחתי מזה, הנה זה לסעיפים 3 ו4 (זה כולל גם את סעיף 1 ו2, מקווה שהבנתי את השאלה נכון)
import java.util.scanner;
public class fourdigitnumber {
public static void main(string[] args) {
scanner scanner = new scanner(system.in);
system.out.print("enter a four-digit number: ");
int number = scanner.nextint();
system.out.println("the number is: " + number);
int digit1 = number / 1000;
int digit2 = (number / 100) % 10;
int digit3 = (number / 10) % 10;
int digit4 = number % 10;
// part a: largest digit
int largestdigit = math.max(math.max(digit1, digit2), math.max(digit3, digit4));
system.out.println("largest digit: " + largestdigit);
// part b: smallest digit
int smallestdigit = math.min(math.min(digit1, digit2), math.min(digit3, digit4));
system.out.println("smallest digit: " + smallestdigit);
// part c: average of digits
double average = (digit1 + digit2 + digit3 + digit4) / 4.0;
system.out.println("average of digits: " + average);
// part d: sum of squares of digits
int sumofsquares = (digit1 * digit1) + (digit2 * digit2) + (digit3 * digit3) + (digit4 * digit4);
system.out.println("sum of squares of digits: " + sumofsquares);
}
}
זה לשאלה 4:
import java.util.scanner;
public class threedigitnumber {
public static void main(string[] args) {
scanner scanner = new scanner(system.in);
system.out.print("enter a three-digit number: ");
int number = scanner.nextint();
system.out.println("the number is: " + number);
number = math.abs(number);
int digit1 = number / 100;
int digit2 = (number / 10) % 10;
int digit3 = number % 10;
double sumofsquareroots = math.sqrt(digit1) + math.sqrt(digit2) + math.sqrt(digit3);
system.out.println("sum of square roots of digits: " + sumofsquareroots);
}
}
import java.util.scanner;
public class threedigitnumber {
public static void main(string[] args) {
scanner scanner = new scanner(system.in);
system.out.print("enter a three-digit number: ");
int number = scanner.nextint();
system.out.println("the number is: " + number);
number = math.abs(number);
int digit1 = number / 100;
int digit2 = (number / 10) % 10;
int digit3 = number % 10;
double sumofsquareroots = math.sqrt(digit1) + math.sqrt(digit2) + math.sqrt(digit3);
system.out.println("sum of square roots of digits: " + sumofsquareroots);
}
}
באותו הנושא: