Şimdi Ara

(acil)Java Ödevimde takıldığım noktalar var yardımcı olur musunuz )

Daha Fazla
Bu Konudaki Kullanıcılar: Daha Az
1 Misafir - 1 Masaüstü
5 sn
4
Cevap
0
Favori
206
Tıklama
Daha Fazla
İstatistik
  • Konu İstatistikleri Yükleniyor
0 oy
Öne Çıkar
Sayfa: 1
Giriş
Mesaj
  • Herkese merhaba arkadaşlar biz okulda java acm(library) öğreniyoruz. Ve hoca bununla ilgili her hafta ödev veriyor. Ben ödevi anlasamda bir türlü istenilen sonuca ulaşamiyorum. Acaba java konusunda bilgi sahibi olan arkadaşlar yardımcı olabilirler mi şimdiden teşekkürler.

    soru su;

    Write a Java method named checkValidity which takes an integer array as parameter and
    returns boolean value. The method/s must complete following tasks:


    (a) The array length should be 16 at most. So you need to check the length first. If the length of the array
    is odd, then you should double the number that in even index (index starts at 1). If the length of the
    array is even, then you should double the odd index’s number (index starts at 0).

    Example01: {1,2,3,4}

    Example02: {3,5,7,2,2}

    Example03: {0,0,0,5,7,0}

    (b) If the number that is doubled, is greater than 9, you should replace the number with the sum of the
    digits (you may need a helper function to sum digits).

    {1,2,3,4} → {2,2,6,4} //no need to digitsum

    {3,5,7,2,2} → {3,1,7,4,2} //5*2=10 digitsum=1

    {0,0,0,5,7,0} → {0,0,0,5,5,0} // 7*2 = 14 digitsum= 5

    (c) After that sum all the numbers.

    {2,2,6,4}→ 2+2+6+4 =14

    {3,1,7,4,2} → 3+1+7+4+2 = 17

    {0,0,0,5,5,0} → 5+5 = 10

    d-) Finally, divide this sum with 10 and if the remainder is equal to zero, this number is valid (true),
    otherwise not a valid number (false).


    false

    false

    true







  •  
    import java.util.Scanner;


    public class Main {

    public static void main(String[] args) {

    Scanner scanner = new Scanner(System.in);

    System.out.println("Enter the length of the array: ");

    int length = scanner.nextInt();

    int[] A = new int[length];

    for (int i = 0; i < length; i++) {

    System.out.println("Enter the element #" + (i + 1));

    A[i] = scanner.nextInt();

    }

    System.out.println(checkValidity(A));

    }

    private static boolean checkValidity(int A[]) {

    if (A.length > 16)

    return false;

    if (A.length % 2 == 1)

    for (int i = 1; i < A.length; i += 2)

    A[i] *= 2;

    else

    for (int i = 0; i < A.length; i += 2)

    A[i] *= 2;

    for (int i = 0; i < A.length; i++)

    if (A[i] >= 10) {

    int sum_of_digits = 0;

    while (A[i] > 0) {

    sum_of_digits += A[i] % 10;

    A[i] = A[i] / 10;

    }

    A[i] = sum_of_digits;

    }

    int sum_of_elements = 0;

    for (int aA : A) sum_of_elements += aA;

    return (sum_of_elements % 10 == 0);

    }

    }




  • Bilgi Universitesi odevi.
    Odevleri kendiniz yapin. Takildiginiz zaman da asistaniniza, hocaniza sorun. Cevap alamazsaniz gelin burada sorun.
    Sonra kendinize nasil "muhendis" diyeceksiniz ?

    < Bu ileti tablet sürüm kullanılarak atıldı >
  • peki arkadaşlar bu kodun en başına import acm.program.*; yazıp applet olarak çalıştırabilecek olan varmı
  • 
Sayfa: 1
- x
Bildirim
mesajınız kopyalandı (ctrl+v) yapıştırmak istediğiniz yere yapıştırabilirsiniz.