Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package practical04;
- public class Question01 {
- public static void main(String[] args) {
- int a=2;
- while(a<=16){
- System.out.print(a + " ");
- a+=2;
- }
- System.out.println();
- int b = 16;
- do{
- System.out.print(b + " ");
- b/=2;
- }while(b >=1 );
- System.out.println();
- int c = 0;
- for(c = 0; c >-10; c--){
- System.out.print(c + " ");
- }
- System.out.println();
- }
- }
- package practical04;
- public class Question02 {
- public static void main(String[] args) {
- int multa=0, multb=0, multc=0;
- while(multa <= 1000){
- System.out.println(multa);
- multa+=5;
- }
- System.out.println("*************************************************");
- do{
- System.out.println(multb);
- multb+=5;
- }while(multb <= 1000);
- System.out.println("*************************************************");
- for(multc=0; multc<=1000; multc+=5){
- System.out.println(multc);
- }
- System.out.println("*************************************************");
- }
- }
- package practical04;
- import java.util.Scanner;
- public class Question03 {
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- int a=1, sum = 0;
- while(a<=5){
- System.out.print("number " + a + " : ");
- int b = input.nextInt();
- a++;
- sum+=b;
- }
- System.out.println("Sum of numbers: " + sum);
- do{
- System.out.print("number " + a + " : ");
- int b = input.nextInt();
- a++;
- sum+=b;
- }while(a<=5);
- System.out.println("Sum of numbers: " + sum);
- for (a=1; a<=5; a+=1){
- System.out.print("number " + a + " : ");
- int b = input.nextInt();
- sum+=b;
- }
- System.out.println("Sum of numbers: " + sum);
- }
- }
- package practical04;
- public class Question04 {
- public static void main(String[] args) {
- int n = 0, n2 = 1;
- while (n2 <= 15000) {
- n2 = n * n;
- System.out.println(n);
- n++;
- }
- n-=1;
- System.out.println("The smallest integer is " + n);
- }
- }
- package practical04;
- import javax.swing.JOptionPane;
- public class Question05 {
- public static void main(String[] args) {
- int num;
- do {
- num = Integer.parseInt(JOptionPane.showInputDialog("Enter a number"));
- if (num <= 100 ||num >= 200) {
- JOptionPane.showMessageDialog(null, "Pls enter a number between 100 and 200!", "Error", JOptionPane.ERROR_MESSAGE);
- }
- }while(num <= 100 || num >= 200);
- JOptionPane.showMessageDialog(null, "End of program!");
- }
- }
- package practical04;
- import javax.swing.JOptionPane;
- public class Question06 {
- // Practical 04 (Unmodified)
- // public static void main(String[] args) {
- // int num, mult;
- // String output = "";
- // String output2 = "";
- //
- // for (num = 1; num <= 12; num++) {
- // mult = num*5;
- // output = num + " x 5 = " + mult + "\n";
- // output2 += output;
- // }
- //
- // JOptionPane.showMessageDialog(null, output2);
- // }
- // below = modified for practical 05 //
- public static void printTable(){
- int num, mult;
- String output = "";
- String output2 = "";
- for (num = 1; num <= 12; num ++){
- mult = num*5;
- output = num + " x 5 = " + mult + "\n";
- output2 += output;
- }
- JOptionPane.showMessageDialog(null, output2);
- }
- public static void main(String[] args) {
- printTable();
- }
- }
- package practical04;
- import javax.swing.JOptionPane;
- public class Question07 {
- public static void main(String[] args) {
- int fnum = Integer.parseInt(JOptionPane.showInputDialog(null, "Enter 1st number", "Example", JOptionPane.INFORMATION_MESSAGE));
- int snum = Integer.parseInt(JOptionPane.showInputDialog(null, "Enter 2nd number", "Example", JOptionPane.INFORMATION_MESSAGE));
- int oddNum;
- String print=" ";
- String print2=" ";
- for (oddNum = fnum; oddNum < snum; oddNum += 1) {
- if (oddNum % 2 == 0) {
- } else {
- print = oddNum + " \n";
- print2 += print;
- }
- }
- JOptionPane.showMessageDialog(null,"Odd numbers between " + fnum + " & " + snum + "\n"
- +print2);
- }
- }
- package practical04;
- import javax.swing.JOptionPane;
- public class Question08 {
- public static void main(String[] args) {
- int a;
- do {
- a = Integer.parseInt(JOptionPane.showInputDialog("Enter any number or \n (0) to quit."));
- if (a == 0) {
- } else {
- {
- if (a % 5 == 0) {
- JOptionPane.showMessageDialog(null, a + " is divisble by 3 but not 5? false");
- } else {
- JOptionPane.showMessageDialog(null, a + " is divisble by 3 but not 5? true");
- }
- }
- }
- } while (a > 0);
- JOptionPane.showMessageDialog(null, "Program terminated");
- }
- }
- package practical04;
- public class Question10 {
- public static void main(String[] args) {
- int total = 0; // initialize total
- int count = 1;
- while (count < 11) { // repeat for 10 times
- int randomInt;
- do {
- // generate a random number from 0 to 8
- randomInt = (int) (Math.random() * 9);
- } while (randomInt >= 0^randomInt % 2 == 0 ); // repeat if random number is not even
- System.out.println("Number " + count + " : " + randomInt); // print out random even number
- total += randomInt; // increase total
- count++;
- }
- double average = total / (count-1); // compute average
- System.out.println("Average is " + average); // print out average
- } // end main
- } // end class
Add Comment
Please, Sign In to add comment