Professional Documents
Culture Documents
Name:: Sap ID: Assignment #: Course: Date
Name:: Sap ID: Assignment #: Course: Date
Question 1:
package labassignment1;
import java.util.Scanner;
/**
*
* @author Awais
*/
public class Lab_Q1 {
public static void main(String args[]) {
float temp;
String[]
city={"Lahore","Sargodha","Kasur","Sialkot","Gojra","Bhalwal","Faisalabad","Raiwind","Chiniot","khush
aab"};
Scanner sc =new Scanner(System.in);
float[] city_temp= new float[10];
char choice;
System.out.println("In which format do you want to enter temperature? c/f");
choice = sc.next().charAt(0);
for(int i=0;i<10;i++) {
System.out.print("Enter temperature of " + city[i] + " in Celcius: ");
city_temp[i]=sc.nextFloat();
}
if(choice == 'c') {
for(int i=0; i<10; i++) {
temp = ((city_temp[i] * 9/5) + 32);
System.out.println("Temperature of city " + city[i] + " is " + temp + " degree Farenheit");
}
}
else if (choice == 'f') {
for(int i=0; i<10; i++) {
temp = ((city_temp[i] - 32) * 5/9);
System.out.println("Temperature of city " + city[i] + " is " + temp + " degree Celcius");
}
}
else{
System.out.println("You have enter wrong choice.");
}
}
}
Output:
Question 2:
package labassignment1;
import javax.swing.*;
/**
*
* @author Awais
*/
public class Lab_Q2 {
Output: