Professional Documents
Culture Documents
Java 4
Java 4
Q1. "Write a program which accepts the values from console ,use method overloading and
overriding concept to display the results by calculating largest values from the variables
package Assignments;
import java.util.Scanner;
}
Output:
Enter 3 numbers
123
2
3
Dog is eating
package files;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.InputMismatchException;
import java.util.Scanner;
Scanner infile;
try {
while(infile.hasNext()) {
input=infile.nextInt();
sum+=input;
System.out.println(sum);
infile.close();
catch(FileNotFoundException ex) {
System.out.println(ex.getMessage());
catch(InputMismatchException ex) {
System.out.println(ex.getMessage());
Q. Writing Files
package files;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
try {
pw.print("Hello There!\n");
pw.close();
catch(FileNotFoundException ex){