Question: I have this code it works and it open the PDF file but it opens only one file like it does not go to the

I have this code it works and it open the PDF file but it opens only one file like it does not go to the other one if I type the other PDF name I made IF statement but I need help with that to make the coices work so I will be having a choice what to open.

Thanks

import java.io.File; import java.awt.Desktop; import java.util.Scanner;

public class PDF { public static void main (String args[])throws Exception { System.out.println("Enter the PDF file Name"); try{ int number1 =1; int number2 =2; int number3 =3; Scanner number = new Scanner(System.in); String name = number.nextLine(); System.out.println(name); if (number1 ==1) { Desktop.getDesktop().open(new File("C:\\Test.pdf")); } else if (number2 ==2) Desktop.getDesktop().open(new File("C:\\Test1.pdf")); else if (number3 ==3){ Desktop.getDesktop().open(new File("C:\\Tes3.pdf")); } } catch(Exception e) { System.out.println(e); } } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!