Javalab - 2 Inputs: Import Java - Util.scanner
Javalab - 2 Inputs: Import Java - Util.scanner
LAB
JavaLab_2
%Lab2_1:
INPUTS
import java.util.Scanner;
public class Reading1 { public static void main(String[] args) { Scanner scan = new Scanner(System.in); double inches = scan.nextDouble(); double centimeters = inches * 2.54; System.out.println(inches +"in =" + centimeters + "cm"); } }
%Lab2_2:
To find the sum of two integers.
import javax.swing.JOptionPane ;
public class example { public static void main(String[] args) {
JOptionPane.PLAIN_MESSAGE);
[] J A V A
LAB
%Lab2_3:
To find the sum from 1 to n import javax.swing.JOptionPane; public class T2 { public static void main(String[] args) { String S; int A , sum = 0; S = JOptionPane.showInputDialog( "Enter integer : " ); A = Integer.parseInt( S ); for (int i=1 ; i<= A; i++) sum = sum + i ; JOptionPane.showMessageDialog( null, "1 + 2 + 3 +..+ "+A +"="+ sum, "summation", JOptionPane.INFORMATION_MESSAGE ); System.exit( 0 ); } }
%Lab2_4:
Write a program to convert F into its equivalent centigrade temperature. import javax.swing.JOptionPane; public class temp { public static void main(String[] args) { String S; double centi, fht ; S = JOptionPane.showInputDialog( "Enter integer : " ); fht = Integer.parseDouble( S ); centi = (fht 32 ) * 5 / 9 ; JOptionPane.showMessageDialog( null, fht +" F = " + centi + degree, "Temperature", JOptionPane.INFORMATION_MESSAGE ); System.exit( 0 ); System.out.println("Centigrade equivalent to 69 F is " + centi + " C"); } }
Try this
Write a program to take input and calculate interest rate (10%) for giving loan. Write a program to read the radius and length of a cylinder and computes its volume.
------------------------------------------------------------------------------------------------------------------------------------------------Dr Mohammed Fadhl 2