Solution:
Import the Scanner package and create a new class
import java.util.Scanner; { public class Input{ static Scanner sc = new Scanner(System.in); public static void main(String[] args) {
Take the student name as a string.
System.out.print("Enter student name: "); String name = sc.nextLine();
Take the university name as a string.
System.out.print("Enter Name of the University: "); String uni = sc.nextLine();
Take the student's age as an integer.
System.out.print("Enter Age: "); int age = sc.nextInt();
Print out the student details.
System.out.println("Here is your ID"); System.out.println("*********************************"); System.out.println("Name: " + name); System.out.println("University: " + uni); System.out.println("Age: " + age); System.out.println("*********************************"); } } }
Solution:
Right-click the src folder and select New | Class.
Enter PeachCalculator as the class name, and then click OK.
Import the java.util.Scanner package:
import java.util.Scanner;
In the main() enter the following:
public class PeachCalculator{ static Scanner sc = new Scanner(System.in); public static void main(String[] args) { System.out.print("Enter the number of peaches picked: "); int numberOfPeaches = sc.nextInt(); int numberOfFullBoxes = numberOfPeaches / 20; int numberOfPeachesLeft = numberOfPeaches - numberOfFullBoxes * 20; System.out.printf("We have %d full boxes and %d peaches left.", numberOfFullBoxes, numberOfPeachesLeft); } }
Run the main program.
The output should be similar to:
Enter the number of peaches picked: 55 We have 2 full boxes and 15 peaches left.