Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: There's a problem in line 43 i need help

  1. #1
    Junior Member
    Join Date
    Apr 2022
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Exclamation There's a problem in line 43 i need help

    import java.util.Scanner;

    public class fibonacci {

    // fibonacci
    static long[] fibonacciCache;

    // palindrome
    static String temp = "";
    public static String reverseString(String word, int index) {

    if(index >= 0) {
    temp = temp + word.charAt(index--);
    reverseString(word, index);
    }
    return temp;
    }

    public static void main(String[] args) {


    // 1
    String completeName = "XXX XX XXX";
    String birthdate = "XXX XX XXX";
    String contactNumber = "XXX XX XXX";
    String emailAddress = "XXX XX XXX";
    String address = "XXX XX XXX";

    if(completeName.equals("XXX XX XXX")) {
    System.out.println("————————————BASIC PROFILE———————————");
    System.out.println("Complete Name : " + completeName);
    System.out.println("Birthdate : " + birthdate);
    System.out.println("Contact Number: " + contactNumber);
    System.out.println("Email Address : " + emailAddress);
    System.out.println("Address : " + address);
    System.out.println();
    System.out.println();

    // 2
    System.out.println("————————————NAME AND AGE————————————");
    static void checkAge (String name int age {
    String name = "XXX";
    int age;
    checkAge(18);

    // If age is greater than, or equal to, 18, print "hi"
    if (age > 18) {
    System.out.println("Hi " + name + "," + "you are an aduld");

    // If age is less than 18, print "hello"
    } else {
    System.out.println("Hello " + name + "," + "you are still a child");
    }

    }


    // 3
    double sum = AreaOfABox(16.5, 16.5);
    System.out.println(sum);

    // 4
    System.out.println(absoluteVlue(89, 90, 94, 3));
    System.out.println(percentageValue(91, 100, 50, 60));

    // 5
    System.out.println();
    System.out.println();
    System.out.prinln("——————————FIBONACCI SERIES——————————");
    int n = 15;

    fibonacciCache = new long[n + 1];
    for(int i = 0; i <= n; i++) {
    System.out.print(fibonacci(i) + " ");
    }

    // 6
    System.out.println();
    System.out.println();
    System.out.println();
    System.out.println("—————————————PALINDROME——————— ——————");
    String word, result;
    Scanner sc = new Scanner(System.in);
    System.out.print("Enter string: ");
    word = sc.nextLine();

    result = reverseString(word, word.length() - 1);

    if(result.equals(word)) {
    System.out.print("• The word " + "'" + word + "'" + " is palindrome!");
    }
    else {
    System.out.print("• The word " + word + " is not palindrome!");
    }

    }

    }

    static double AreaOfABox(double width, double length) {
    System.out.println("———————————AREA OF A BOX————————————");
    System.out.print("Square Per Meter: ");
    return width + length;
    }


    static int absoluteVlue(int Q1, int Q2, int Q3, int Q4) {
    System.out.println();
    System.out.println();
    System.out.println("———————————STUDENT GRADES———————————");
    System.out.print("Absolute Value : ");
    return (Q1 + Q2 + Q3) / Q4;
    }

    static double percentageValue(double G, double dividend, double multiplier, double addenen) {
    System.out.print("Percentage Value: ");
    return (((G / dividend) * multiplier) + addenen);
    }



    static long fibonacci(int n) {
    if(n <= 1) {
    return n;
    }
    if(fibonacciCache[n] != 0) {
    return fibonacciCache[n];
    }

    long nthFibonacciNumber = ((n - 1) + (n - 2));
    fibonacciCache[n] = nthFibonacciNumber;
    return nthFibonacciNumber;

    }
    }
    Last edited by 8022pie; April 18th, 2022 at 03:12 PM.

  2. #2
    Member
    Join Date
    Apr 2022
    Posts
    36
    Thanks
    0
    Thanked 8 Times in 8 Posts

    Default Re: There's a problem in line 43 i need help

    this code is full of errors, it is quite difficult to fix them all but i will try.

  3. The Following User Says Thank You to andreaita44 For This Useful Post:

    8022pie (April 20th, 2022)

  4. #3
    Member
    Join Date
    Apr 2022
    Posts
    36
    Thanks
    0
    Thanked 8 Times in 8 Posts

    Default Re: There's a problem in line 43 i need help

    import java.time.LocalDate;
    import java.util.Scanner;
     
    public class fibonacci {
     
        //objects and variabes
        public static final Scanner input = new Scanner(System.in);
        private static LocalDate currentDate = LocalDate.now();
        private static int currentYear = currentDate.getYear();
        private static final int minYear = 1870;
     
        public static void main(String[] args) {
            //variables
            int year, month, day;
     
            System.out.print("Enter your name: ");
            String name = input.nextLine();
            System.out.print("Enter your surname: ");
            String surname = input.nextLine();
            String completeName = name + " " + surname;
     
            do{
                System.out.print("Enter your birthday year: ");
                year = input.nextInt();
                if(year < minYear || year > currentYear) {
                    System.out.println("Error: the year must be between " + minYear + " and " + currentYear + ".");
                }
            } while(year < 0 || year > currentYear);
            do{
                System.out.print("Enter your birthday month: ");
                month = input.nextInt();
                if(month < 1 || month > 12) {
                    System.out.println("Error: the month must be between 1 and 12.");
                }
            } while(month < 1 || month > 12);
            do{
                System.out.print("Enter your birthday day: ");
                day = input.nextInt();
                if(!isDayValid(day, month, year)) {
                    System.out.println("Error: the day in " + month + "" + year + " does not exist.");
                }
            } while(!isDayValid(day, month, year));
            String birthdate = day + " " + month + " " + year;
            int age = currentYear-year;
     
            String contactNumber = "XXX XX XXX";
            String emailAddress = "XXX XX XXX";
            String address = "XXX XX XXX";
     
            if(completeName.equals("XXX XX XXX")) {
                System.out.println("————————————BASIC PROFILE———————————");
                System.out.println("Complete Name : " + completeName);
                System.out.println("Birthdate : " + birthdate);
                System.out.println("Contact Number: " + contactNumber);
                System.out.println("Email Address : " + emailAddress);
                System.out.println("Address : " + address);
                checkAge(name, age);
            }
     
            System.out.println(AreaOfABox(16.5, 16.5));
            System.out.println(absoluteValue(89, 90, 94, 3));
            System.out.println(percentageValue(91, 100, 50, 60));
     
            System.out.println("\n\n——————————FIBONACCI SERIES————————————");
            int n = 15;
            long[] fibonacciCache = fibonacci(n);
            for(long element : fibonacciCache) {
                System.out.print(element + " ");
            }
     
            System.out.println("\n\n—————————————PALINDROME—————————————");
            if(input.hasNext()){
                input.nextLine();
            }
            String word = input.nextLine();
            if(isPalindrome(word)) {
                System.out.println("• The word '" + word + "' is palindrome!");
            }
            else {
                System.out.println("• The word " + word + " is not palindrome!");
            }
     
        }
        public static boolean isDayValid(int day, int month, int year){
            if(year > 0 && month > 0 && month < 13){
                switch(month){
                    case 4: 
                    case 6:
                    case 9:
                    case 11: return day > 0 && day < 31;
                    case 2: if (year % 4 == 0) {return day > 0 && day < 29;}
                            else if (year % 100 != 0) {return day > 0 && day < 30;}
                            else if (year % 400 != 0) {return day > 0 && day < 29;}
                            else {return day > 0 && day < 30;}
                    default: return day > 0 && day < 32;
                }
            }
            return false;
        }
     
        public static void checkAge(String name, int age) {
            System.out.println("————————————NAME AND AGE————————————");
            if(age>18){
                // If age is greater than, or equal to, 18, print "hi"
                System.out.println("Hi " + name + ", you are an aduld");
            } else {
                // If age is less than 18, print "hello"
                System.out.println("Hello " + name + ", you are still a child");
            }
        }
     
        public static double AreaOfABox(double width, double length) {
            System.out.println("\n\n———————————AREA OF A BOX————————————");
            System.out.print("Square Per Meter: ");
            return width + length;
        }
     
        public static boolean isPalindrome(String word) {
            return word.equals(reverseString(word));
        }
     
        public static String reverseString(String string) {
            String tmp = "";
            for(int i = string.length() - 1; i >= 0; i--){
                tmp += string.charAt(i);
            }
            System.out.println(tmp);
            return tmp;
        }
     
        public static long[] fibonacci(int n) {
            //I edit this beacuse your fibonacci was incorrect
            long[] fibonacci = new long[n];
            int n1 = 1, n2 = 1;
            for(int i = 0; i < n; i++){
                if(i == 0 || i == 1){
                    fibonacci[i] = 1;
                }else{
                    fibonacci[i] = fibonacci[i-2] + fibonacci[i-1];
                }
            }
            return fibonacci;
        }
        public static int absoluteValue(int Q1, int Q2, int Q3, int Q4) {
            System.out.println("\n\n———————————STUDENT GRADES———————————");
            System.out.print("Absolute Value : ");
            return (Q1 + Q2 + Q3) / Q4;
        }
        public static double percentageValue(double G, double dividend, double multiplier, double addenen) {
            System.out.print("Percentage Value: ");
            return (((G / dividend) * multiplier) + addenen);
        }
    }

  5. The Following User Says Thank You to andreaita44 For This Useful Post:

    8022pie (April 20th, 2022)

  6. #4
    Junior Member
    Join Date
    Apr 2022
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: There's a problem in line 43 i need help

    Whooa Thanks a lot pal i mean totally cheers

Similar Threads

  1. Line string problem
    By ridg18 in forum Java Theory & Questions
    Replies: 1
    Last Post: November 1st, 2012, 05:30 AM
  2. Re: Problem with BufferedReader : readLine() cut the line
    By caveden in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: August 10th, 2012, 08:46 AM
  3. Problem with BufferedReader : readLine() cut the line
    By mfgagne73 in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: May 3rd, 2012, 10:18 AM
  4. Replies: 10
    Last Post: September 16th, 2011, 07:49 PM
  5. A problem with command line compilation
    By goodguy in forum Java Theory & Questions
    Replies: 4
    Last Post: August 2nd, 2010, 10:58 AM