Repository navigation
Expand file tree
/
Copy pathworkingonmethods
More file actions
68 lines (45 loc) · 1.9 KB
/
Copy pathworkingonmethods
File metadata and controls
68 lines (45 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package com.methods.java;
import javax.swing.*;
public class method1 {
public static void main(String[] args) {
String hehe=JOptionPane.showInputDialog("enter your first no."); //entry point for no. 1
String old=JOptionPane.showInputDialog("enter your 2nd no. "); //entry point for no. 2
int a1=Integer.parseInt(hehe); //converting string to int
int a2=Integer.parseInt(old);//converting string to int
double avg=ashu(a1,a2, 3); //including method ashu
System.out.println(avg); //prinitng average ( avg=(a+b)/2.0; )
String fluname= ioname(JOptionPane.showInputDialog("enter surname"),
JOptionPane.showInputDialog("enter name")); //entry of name
System.out.println(fluname); //printing full name
System.out.println("\n");
String ol=JOptionPane.showInputDialog("Enter a number betwween 1 to 100"); //boolean entry
int n=Integer.parseInt(ol); //converting entry to int
if ( newsl(n)) {
JOptionPane.showMessageDialog(null, "right number");
}
else //printing statement
{
JOptionPane.showMessageDialog(null, " wrong number" +
"");
}
}
public
static double ashu(int a, int b, int c) { //public method [type- return]
double avg=(a+b)/2.0;
return avg;
}
public static String ioname(String surname, String name) //public method [type- return]
{
final String flname="Name: "+name + "\n" + "Surname: " + surname;
return flname;
}
/**
* This method determines if the no. is >= 1 or <= 100
* @param n it stores the number
* @return it return the boolean state acc to the no. provided
*/
public static boolean newsl( int n) //public method [type- return]
{
boolean sts;
return (n > 1 && n < 100); }
}