我是新手并且正在努力学习java,我需要协助代码。值保持重置为默认值

时间:2018-01-08 15:30:38

标签: java netbeans

请帮助

请帮助我的程序我对编码有点新,我不知道如何解决我的问题。代码工作没有错误,但结果错误。我在几天内写作考试,希望得到一些帮助。

package Practice1.pkg1;

import java.time.Year;
import java.util.Scanner;    

public class Sub1 {    

    public static void main(String[] args) {
        int age = 0;
        String name ="";
        String surname ="";
        int dob = 0;
        int year = Year.now().getValue(); 

        info( name, sur**strong text**name, age);
        calc(age, year, dob);
        result(name, surname, age, year, dob);
    }

    public static void info(String name, String surname, int age) {
        System.out.println("What is your name user?"); 
        Scanner input= new Scanner(System.in);
        name = input.nextLine();
        System.out.println("What is your surname user?"); 
        Scanner input2= new Scanner(System.in);
        surname = input2.nextLine();
        System.out.println("What is your age user?"); 
        Scanner input3= new Scanner(System.in);
        age = Integer.parseInt(input3.nextLine());
    }

    public static void calc(int age, int year, int dob) {
        dob = year - age;
    }

    public static void result(String name, String surname, int age, int year, int dob) {
        System.out.println("Welcome "+name+" "+ surname+" born in "+dob);
        //user in put returns back to default.
    }
}

0 个答案:

没有答案