In: Computer Science
“Java looks good”
2. Write a code in java – create a method “s”. Insert 10 floating-point numbers in it. Using iterator find the sum of those numbers.
3. Write a Java program to read integers (for ex: 2017). Display it one digit per line in reverse order.
7
1
0
2
1).
import javax.swing.JFrame;
import javax.swing.JOptionPane;
public class DialogueBox {
JFrame f;
DialogueBox(){
f=new JFrame();
JOptionPane.showMessageDialog(f,"Java looks
good!");
}
public static void main(String[] args) {
new DialogueBox();
}
}
output:
====
2).
Code:
====
import java.util.ArrayList;
import java.util.Iterator;
public class FloatingIterator {
public static void main(String[] args) {
ArrayList<Double> al = new
ArrayList<Double>();
al.add(1.12);
al.add(2.12);
al.add(3.12);
al.add(4.12);
al.add(5.12);
al.add(6.12);
al.add(7.12);
al.add(8.12);
al.add(9.12);
al.add(10.12);
s(al);
}
public static void s(ArrayList<Double> al)
{
Iterator<Double> it =
al.iterator();
while(it.hasNext()) {
System.out.println(it.next());
}
}
}
output:
=====
3).
import java.util.Scanner;
public class ReverseDigits {
public static void main(String[] args) {
Scanner sc = new
Scanner(System.in);
System.out.print("Enter a number:
");
int input = sc.nextInt();
while(input%10!=input) {
System.out.println(input%10);
input =
input/10;
}
System.out.println(input);
sc.close();
}
}
output:
=====
4).
import java.util.Scanner;
public class FloatBetween {
public static void main(String[] args) {
Scanner sc = new
Scanner(System.in);
System.out.print("Enter a number:
");
double input =
sc.nextDouble();
if(input>150.45 ||
(input>=60.30 && input<=70.25)) {
System.out.println("YES");
}
else {
System.out.println("NO");
}
sc.close();
}
}
output:
====