Question:
Need help in java program, please?
Tukai
2013-07-12 06:01:24 UTC
So,I get a homework of java program from school.Total 4 program and I have done 2 but I can understand the remaining two programs.
Remember all program should be done using Scanner Class.

1.Write a java program to input the temperature in degree Celsius and find in degree Fahrenheit (Using Scanner Class).

2.Write a java program to find if the number of days is 67,then it is equivalent to how many months and days,assuming the no. of days in a month is 30 (Using Scanner Class and without input).

Thanks in advance.
Five answers:
brilliant_moves
2013-07-12 06:44:34 UTC
Here's a solution to question 2:



import java.util.Scanner;



public class MonthsAndDays {



public static void main(String[] args) {



final int DAYS_IN_MONTH = 30;



int months = 0, days = 0;



Scanner scan = new Scanner(System.in);



System.out.print("Enter number of days: ");

days = scan.nextInt();



months = days / DAYS_IN_MONTH;

days %= DAYS_IN_MONTH;



System.out.print(months + " month");

System.out.print(months==1? ", ": "s, "); // singular or plural

System.out.print(days+" day");

System.out.print(days==1? ".": "s."); // singular or plural



}//end main()

}//end class
anonymous
2016-05-20 01:55:49 UTC
Why roll your own when there is in all likelihood a calendar widget you can reuse? By the way, the Java API itself provides many useful classes and interfaces: Date, Calendar, GregorianCalendar, DateFormat, and SimpleDateFormat.
Gopi
2013-07-12 10:24:47 UTC
solution for question 1

---------------------------------------





import java.util.Scanner;



public class CF {



public static void main(String args[]) {

Scanner input = new Scanner(System.in);

System.out.println("Enter the temperature in Celsius: ");

double c = input.nextDouble();

System.out.println(c + " celsius = " + ((c * 9.0 / 5.0) + 32) + " fahrenheit.");

}

}
Puter_Notgeek
2013-07-17 09:14:06 UTC
Well he sure is learning from those just writing his code.

Not a good practice. he isn't learning a thing and you aren't there for test.
History
2013-07-17 02:20:52 UTC
Change Your Question from "Need help in java program, please?" to "see the objectives for my program and write it for me"


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...